From b9d4bef4afad809ce459eeda0035a72481b1b75c Mon Sep 17 00:00:00 2001 From: Krystian Duma Date: Wed, 26 Jul 2023 19:55:19 +0200 Subject: [PATCH] Create 2.eloquent-ulidable.md --- content/3.libraries/2.eloquent-ulidable.md | 36 ++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 content/3.libraries/2.eloquent-ulidable.md diff --git a/content/3.libraries/2.eloquent-ulidable.md b/content/3.libraries/2.eloquent-ulidable.md new file mode 100644 index 0000000..9e2fbd3 --- /dev/null +++ b/content/3.libraries/2.eloquent-ulidable.md @@ -0,0 +1,36 @@ + --- +title: Eloquent ULID-able +type: library +platform: Laravel +github: https://github.com/kduma-OSS/L5-eloquent-ulidable +--- + +# Eloquent ULID-able + +Eases using and generating ulid's in Laravel Eloquent models. + +## Setup +Install it using composer + +```bash +composer require kduma/eloquent-ulidable +``` + +## Prepare models +Inside your model (not on top of file) add following lines: + +```php +use \KDuma\Eloquent\Ulidable; +``` + +In database create `ulid` string field. If you use migrations, you can use following snippet: + +```php +$table->ulid()->unique(); +``` + +## Usage +By default it generates slug on first save. + +- `$model->regenerateUlid()`{lang="php"} - Generate new uuid. (Remember to save it by yourself) +- `Model::whereUlid($ulid)->first()`{lang="php"} - Find by ulid. (`whereUlid` is query scope)