kduma/eloquent-uuidable

Eases using and generating uuid's in Laravel Eloquent models.

v1.0.1 2020-05-06 12:02 UTC

This package is auto-updated.

Last update: 2024-11-29 18:47:03 UTC


README

Latest Stable Version Total Downloads Latest Unstable Version License

Eases using and generating guid's in Laravel Eloquent models.

Setup

Install it using composer

composer require kduma/eloquent-uuidable

Prepare models

Inside your model (not on top of file) add following lines:

use \KDuma\Eloquent\Uuidable;

In database create uuid string field. If you use migrations, you can use following snippet:

$table->uuid('uuid')->unique();

Usage

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';

Packagist

View this package on Packagist.org: kduma/eloquent-uuidable