Package Data | |
---|---|
Maintainer Username: | kblais |
Maintainer Contact: | contact@killianblais.fr (Killian Blais) |
Package Create Date: | 2016-06-02 |
Package Last Update: | 2024-04-16 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-19 03:25:25 |
Package Statistics | |
---|---|
Total Downloads: | 70,722 |
Monthly Downloads: | 691 |
Daily Downloads: | 33 |
Total Stars: | 10 |
Total Watchers: | 2 |
Total Forks: | 5 |
Total Open Issues: | 0 |
A simple library to use UUIDs as your Eloquent model's primary key.
To answer this question, I simply recommend you read this blog post.
Require this package with Composer :
composer require kblais/laravel-uuid
First, your model's column must be a 36 characters column :
$table->char('id', 36);
$table->primary('id');
$table->uuid('id');
$table->primary('id');
Then, just add the Kblais\Uuid\Uuid
trait to your model, and you're done :
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Kblais\Uuid\Uuid;
class User extends Model
{
use Uuid;
}
Version 4 UUIDs are used by default. You can change this by overriding the $uuidVersion & $uuidString
variables. For example :
protected $uuidVersion = 1;
protected $uuidString = ''; // only needed when $uuidVersion is "3 or 5"
The supported UUIDs versions here are "1, 3, 4 and 5".