frictionlessdigital/uuidable
| Install | |
|---|---|
composer require frictionlessdigital/uuidable |
|
| Latest Version: | 12.1.0 |
| License: | MIT |
| Last Updated: | Sep 8, 2026 |
| Links: | GitHub · Packagist |
FLS :: Uuidable
Add UUID behavior to your Eloquent models.
Installation
composer require "frictionlessdigital/uuidable":"^1.0"
Note that root namespace for the package is Fls not Frictionlessditial.
Config
The package does not require configuration.
Integration
To add behavior to your model, simply import the trait:
use Fls\Uuidable\Uuidable;
class User extends Model
{
use Uuidable;
...
}
If you want to update the field to within which the UUID is stored, define a static model propery like so:
use Fls\Uuidable\Uuidable;
class User extends Model
{
use Uuidable;
...
/**
* Name of the field to to store the UUID
*
* @var string
*/
const UUID = 'diuu';
}
Usage
Fls\Uuidable\Uuidable trait adds a number of methods to your model:
Uuidable::findByUuid
Similar to find($key), findByUuid($uuid) will locate the first Uuidable model where the value of the fild matches the argument.
$user = User::findByUuid(string $uuid);
You can also pass an array of column you want to hydrate from the database as a second argument:
$user = User::findByUuid(string $uuid, ['email', 'password']);
Under the hood the method relies on whereUuid()
Uuidable::whereUuid()
Scope the model by uuid value. You can use a string value, an array, pass in Arrayable class. N.B. if you pass an Eloquent Collection, it will be parsed for its model keys, which will be passed as a scoping argument.
$builder = User::whereUuid(string $uuid);
or
$builder = User::whereUuid([$uuid]);
or
$builder = User::whereUuid(collect([$uuid]));
or
$builder = User::whereUuid(Users::pluck('uuid'));
Change log
Please see CHANGELOG for more information on what has changed recently.
Testing
$ composer test
Contributing
Please see CONTRIBUTING and CODE_OF_CONDUCT for details.
Security
If you discover any security related issues, please email support@frictionlesssolutions.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
Related Packages
Automatic configuration for Laravel apps to apply Tighten's standard linting & c...
Version History
| Version | Released | PHP | Laravel | License |
|---|---|---|---|---|
| 12.1.0 | ^12.0| | MIT | ||
| 12.0.0 | ^8.1 | ^10.0| | MIT | |
| 1.4 | ^8.1 | ^10.0| | MIT | |
| 1.3.0 | ^8.1 | ^10.0 | MIT | |
| 1.2.0 | ^7.3 | | ^8.0 | | MIT | |
| 1.1.0 | ^7.3 | | ^8.0 | | MIT | |
| 1.0.3 | ^7.3 | | ^8.0 | MIT | |
| 1.0.2 | ^7.3 | | ^8.0 | MIT | |
| 1.0.1 | ^7.3 | | ^8.0 | MIT | |
| 1.0.0 | ^7.3 | | ^8.0 | MIT |