PHP code example of shikachuu / laravel-cuid2

1. Go to this page and download the library: Download shikachuu/laravel-cuid2 library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

shikachuu / laravel-cuid2 example snippets


$id = cuid2();
// or provide an argument with the key size
$id = cuid2(30);
// or call the facade directly
$idFromTheFacade = \Shikachuu\LaravelCuid2\Facades\Cuid2::generate(30);

\Shikachuu\LaravelCuid2\Facades\Cuid2::validate($id);

Validator::validate(['cuid' => 'qo08kg4ogogcc4sowwskkwko'], ['cuid' => 'cuid2']);



declare(strict_types=1);

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class () extends Migration {
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('tests', function (Blueprint $table): void {
            $table->cuid2()->primary(); // generates a `cuid2` filed to use it as the primary key
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('tests');
    }
};

$table->cuid2('myFieldName');



declare(strict_types=1);

namespace Workbench\App\Models;

use Illuminate\Database\Eloquent\Model;
use Shikachuu\LaravelCuid2\Eloquent\Concerns\HasCuid2;

class Orders extends Model
{
    use HasCuid2;
    protected $primaryKey = 'cuid2';
}
shell
php artisan vendor:publish --provider="Shikachuu\LaravelCuid2\Cuid2ServiceProvider"