Package Data | |
---|---|
Maintainer Username: | gbuckingham89 |
Maintainer Contact: | george@georgebuckingham.com (George Buckingham) |
Package Create Date: | 2017-01-16 |
Package Last Update: | 2023-07-21 |
Home Page: | |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2025-01-22 15:10:15 |
Package Statistics | |
---|---|
Total Downloads: | 4,664 |
Monthly Downloads: | 7 |
Daily Downloads: | 0 |
Total Stars: | 1 |
Total Watchers: | 1 |
Total Forks: | 1 |
Total Open Issues: | 0 |
A simple package for using UUID's with Laravel's Eloquent models. By including the trait on your models, they will autoamtcailly get given a time ordered UUIDv4 for their key (ID) when being persisted to the database.
This package now requires Laravel 5.6+ due to it's use of Str::orderedUuid()
. If you're using an older version of Laravel, please see v1 of this package.
composer require gbuckingham89/eloquent-uuid
Make sure your database table(s) are setup to handle UUID's. Laravel has a method called uuid()
which you can use in your migrations. You will probably want the field to be unique too.
Schema::create('users', function (Blueprint $table) {
$table->uuid('id')->unique();
// Other fields here...
});
At the top of your model(s) you simply need to include a trait:
<?php
namespace App;
use Gbuckingham89\EloquentUuid\Traits\UuidForKey;
use Illuminate\Database\Eloquent\Model;
class User extends Eloquent
{
use UuidForKey;
}
Code and documentation copyright 2018 George Buckingham. Code released under the MIT License.