juniorb2ss / eloquent-uuid
实现 Eloquent ORM 中 UUID 的特质
1.0.1
2017-08-08 15:47 UTC
Requires
- php: ^7.0
- illuminate/support: ~4|~5
- ramsey/uuid: ^3.4
Requires (Dev)
- doctrine/dbal: ~2.3
- orchestra/database: ^3.4
- orchestra/testbench: ~3.0
- phpunit/phpunit: ~4.0||~5.0
- squizlabs/php_codesniffer: ^2.3
This package is not auto-updated.
Last update: 2024-09-15 04:20:29 UTC
README
juniorb2ss/eloquent-uuid
提供了一个简单的特质,用于在 ORM 中实现 UUID。
安装
您可以通过 composer 安装此包
$ composer require juniorb2ss/eloquent-uuid~1.*
Eloquent 特质
use juniorb2ss\EloquentUuid\EloquentUuidTrait; class User extends Authenticatable { use Notifiable, EloquentUuidTrait; /** * UUID Column name used * * @var string * @optional */ protected $uuidKey = 'uuid'; }
UUID 列
您需要在表模型中创建新的列,例如 uuid
或者在 uuidKey
模型属性中定义的自定义名称
示例
$fields = $request->only(['email', 'name', 'password']); $user = User::create($fields); // Creating user with auto-inject uuid field dump($user->toArray()); /*[ "id" => "1" "uuid" => "723e4628-7c35-11e7-89b1-0242bfc0df57", "name" => "Magdalena Zboncak" "email" => "nitzsche.katherine@gulgowski.com" ]*/
基于 UUID 的作用域
use App\User; $user = (new User)->onUuid('aae5f3f1-0f22-4a8b-9291-d2a9649d1490') ->firstOrFail();
测试
composer run test
变更日志
请参阅 变更日志 以获取更多关于最近更改的信息。
致谢
许可证
MIT 许可证 (MIT)。请参阅 许可证文件 以获取更多信息。