-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |