forked from kduma-OSS/LV-eloquent-uuidable
-
Notifications
You must be signed in to change notification settings - Fork 1
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
14 additions
and
20 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 |
---|---|---|
@@ -1,36 +1,30 @@ | ||
# L5-eloquent-uuidable | ||
[![Latest Stable Version](https://poser.pugx.org/kduma/eloquent-uuidable/v/stable.svg)](https://packagist.org/packages/kduma/eloquent-uuidable) | ||
[![Total Downloads](https://poser.pugx.org/kduma/eloquent-uuidable/downloads.svg)](https://packagist.org/packages/kduma/eloquent-uuidable) | ||
[![Latest Unstable Version](https://poser.pugx.org/kduma/eloquent-uuidable/v/unstable.svg)](https://packagist.org/packages/kduma/eloquent-uuidable) | ||
[![License](https://poser.pugx.org/kduma/eloquent-uuidable/license.svg)](https://packagist.org/packages/kduma/eloquent-uuidable) | ||
# L5-eloquent-ulidable | ||
[![Latest Stable Version](https://poser.pugx.org/kduma/eloquent-ulidable/v/stable.svg)](https://packagist.org/packages/kduma/eloquent-ulidable) | ||
[![Total Downloads](https://poser.pugx.org/kduma/eloquent-ulidable/downloads.svg)](https://packagist.org/packages/kduma/eloquent-ulidable) | ||
[![Latest Unstable Version](https://poser.pugx.org/kduma/eloquent-ulidable/v/unstable.svg)](https://packagist.org/packages/kduma/eloquent-ulidable) | ||
[![License](https://poser.pugx.org/kduma/eloquent-ulidable/license.svg)](https://packagist.org/packages/kduma/eloquent-ulidable) | ||
|
||
Eases using and generating guid's in Laravel Eloquent models. | ||
Eases using and generating ulid's in Laravel Eloquent models. | ||
|
||
# Setup | ||
Install it using composer | ||
|
||
composer require kduma/eloquent-uuidable | ||
composer require kduma/eloquent-ulidable | ||
|
||
# Prepare models | ||
Inside your model (not on top of file) add following lines: | ||
|
||
use \KDuma\Eloquent\Uuidable; | ||
use \KDuma\Eloquent\Ulidable; | ||
|
||
In database create `uuid` string field. If you use migrations, you can use following snippet: | ||
In database create `ulid` string field. If you use migrations, you can use following snippet: | ||
|
||
$table->uuid('uuid')->unique(); | ||
$table->ulid()->unique(); | ||
|
||
# Usage | ||
By default it generates slug on first save. | ||
By default, it generates slug on first save. | ||
|
||
- `$model->regenerateUuid()` - Generate new uuid. (Remember to save it by yourself) | ||
- `Model::whereUuid($uuid)->first()` - Find by guid. (`whereUuid` is query scope) | ||
|
||
# Upgrade from 1.x/2.x version of `kduma/eloquent-guidable` | ||
|
||
Add following line to yours models to switch from using `uuid` column name to `guid` as it was used in previous versions: | ||
|
||
protected $uuid_field = 'guid'; | ||
- `$model->regenerateUlid()` - Generate new ulid. (Remember to save it by yourself) | ||
- `Model::whereUlid($ulid)->first()` - Find by ulid. (`whereUlid` is query scope) | ||
|
||
# Packagist | ||
View this package on Packagist.org: [kduma/eloquent-uuidable](https://packagist.org/packages/kduma/eloquent-uuidable) | ||
View this package on Packagist.org: [kduma/eloquent-ulidable](https://packagist.org/packages/kduma/eloquent-ulidable) |