lucadello91/eloquent-uuid
最新稳定版本:1.5.0
Composer 安装命令:
composer require lucadello91/eloquent-uuid
包简介
Laravel Eloquent Model trait for using UUID on primary key
README 文档
README
Eloquent UUID
An Eloquent UUID Trait to use with Laravel > 5.6
Installation
composer require lucadello91/eloquent-uuid
In your models
For using uuid in your Eloquent Model, just put use UuidModelTrait;:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Lucadello91\EloquentUuid\UuidModelTrait;
class User extends Model
{
use UuidModelTrait;
}
This package will use UUID v4 values by default.
You can use uuid1, uuid3, uuid4, uuid5 or ordered by setting the protected property $uuidVersion in your Eloquent Model.
<?php namespace App; use Illuminate\Database\Eloquent\Model; use Lucadello91\EloquentUuid\UuidModelTrait; class Post extends Model { use UuidModelTrait; protected $uuidVersion = 'uuid5'; }
Database Schema
When using UuidModelTrait, you have to use uuid your schema :
Schema::create('users', function (Blueprint $table) {
$table->uuid('id')->primary();
//...
});
Binary Uuid
If you prefer to use a binary UUID in your database, you just need to cast your primary key to uuid
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Lucadello91\EloquentUuid\UuidModelTrait;
class User extends Model
{
use UuidModelTrait;
protected $keyType = 'uuid';
//or
protected $casts = [
'id' => 'uuid',
];
}
Running tests
To run the tests, just run composer install and ./vendor/bin/phpunit.
Changelog
Please see CHANGELOG for more information what has changed recently.
Credits
License
The MIT License (MIT). Please see License File for more information.
统计信息
- 总下载量: 8.63k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-11-18