PHP code example of rorecek / laravel-ulid

1. Go to this page and download the library: Download rorecek/laravel-ulid 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/ */

    

rorecek / laravel-ulid example snippets


// config/app.php
'providers' => [
    ...
    Rorecek\Ulid\UlidServiceProvider::class,
];

...

'aliases' => [
    ...
    'Ulid' => Rorecek\Ulid\Facades\Ulid::class,
];
 php
$table->char('id', 26)->primary();
 php
Schema::create('items', function (Blueprint $table) {
  $table->char('id', 26)->primary();
  ....
  ....
  $table->timestamps();
});
 php
// 'HasUlid' trait will automatically generate and assign id field.
$item = Item::create(['name' => 'Awesome item']);
echo $item->id;
// 01brh9q9amqp7mt7xqqb6b5k58