Eases using and generating ulid's in Laravel Eloquent models.
Install it using composer
composer require kduma/eloquent-ulidable
Inside your model (not on top of file) add following lines:
use \KDuma\Eloquent\Ulidable;
In database create ulid
string field. If you use migrations, you can use following snippet:
$table->ulid()->unique();
By default, it generates slug on first save.
$model->regenerateUlid()
- Generate new ulid. (Remember to save it by yourself)Model::whereUlid($ulid)->first()
- Find by ulid. (whereUlid
is query scope)
View this package on Packagist.org: kduma/eloquent-ulidable