1. Go to this page and download the library: Download pelmered/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/ */
pelmered / laravel-ulid example snippets
use Pelmered\LaravelUlid\LaravelUlidServiceProvider;
class Post extends Model implements Ulidable
{
use HasUlid;
//...
}
use Pelmered\LaravelUlid\LaravelUlidServiceProvider;use Pelmered\LaravelUlid\ValueObject\Ulid;
class Post extends Model implements Ulidable
{
use HasUlid;
protected string $ulidPrefix = 'p_';
protected int $ulidTimeLength = 10;
protected int $ulidRandomLength = 16;
protected string $ulidOptions = Ulid::OPTION_UPPERCASE;
//...
}
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
// Create a table with an ULID primary key like this:
Schema::create('users', function (Blueprint $table) {
$table->uLid('id', (new \Workbench\App\Models\User())->getUlidLength())->primary();
});
// or like this:
Schema::create('posts', function (Blueprint $table) {
$table->modelULid('id', User::class)->primary();
});
}
}
ULID::make(); // '1234567890123456789' - Normal ULID
ULID::make('p_', Carbon::parse('2010-11-12 01:02:03')); // 'u_1234567890123456789' - ULID with prefix
ULID::make('p_', 10, 10 ); // 'u_1234567890123456789' - ULID with prefix
ULID::fromModel($model);
ULID::isValidUlid('u_1234567890123456789', $model);
bash
php artisan vendor:publish --tag=ulid-config
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.