| Package Data | |
|---|---|
| Maintainer Username: | binarycabin |
| Maintainer Contact: | jeff@binarycabin.com (Jeff Kilroy) |
| Package Create Date: | 2017-11-14 |
| Package Last Update: | 2024-04-25 |
| Language: | PHP |
| License: | MIT |
| Last Refreshed: | 2025-10-19 15:18:40 |
| Package Statistics | |
|---|---|
| Total Downloads: | 507,935 |
| Monthly Downloads: | 9,895 |
| Daily Downloads: | 49 |
| Total Stars: | 85 |
| Total Watchers: | 0 |
| Total Forks: | 10 |
| Total Open Issues: | 7 |
A wrapper for webpatser/laravel-uuid with additional integration
composer require binarycabin/laravel-uuid
This package adds a very simple trait to automatically generate a UUID for your Models.
Simply add the "\BinaryCabin\LaravelUUID\Traits\HasUUID;" trait to your model:
<?php
namespace App;
use BinaryCabin\LaravelUUID\Traits\HasUUID;
use Illuminate\Database\Eloquent\Model;
class Project extends Model
{
use HasUUID;
}
If your column name is not "uuid", simply add a new property to your model named "uuidFieldName":
protected $uuidFieldName = 'unique_id';
This trait also adds a scope:
\App\Project::byUUID('uuid')->first();
And static find method:
\App\Project::findByUUID('uuid')
A second trait is available if you use your UUIDs as primary keys:
<?php
namespace App;
use BinaryCabin\LaravelUUID\Traits\HasUUID;
use BinaryCabin\LaravelUUID\Traits\UUIDIsPrimaryKey;
use Illuminate\Database\Eloquent\Model;
class Project extends Model
{
use HasUUID, UUIDIsPrimaryKey;
}
It simply tells Laravel that your primary key isn't an auto-incrementing integer, so it will treat the value correctly.