frictionlessdigital / uuidable
无摩擦解决方案 | Uuidable
1.3.0
2023-04-02 16:49 UTC
Requires
- php: ^8.1
- illuminate/support: ^10.0
Requires (Dev)
- fakerphp/faker: ^1.9.1
- friendsofphp/php-cs-fixer: ^3.0
- mockery/mockery: ^1.4.2
- orchestra/testbench: ^6.0 || ^7.0
- phpunit/phpunit: ^9.5||^10.0
README
为您的 Eloquent 模型添加 UUID 行为。
安装
composer require "frictionlessdigital/uuidable":"^1.0"
注意,该软件包的根命名空间是 Fls 而不是 Frictionlessditial。
配置
该软件包不需要配置。
集成
要为您的模型添加行为,只需导入该特性
use Fls\Uuidable\Uuidable; class User extends Model { use Uuidable; ... }
如果您想更新存储 UUID 的字段,可以定义一个静态模型属性,如下所示
use Fls\Uuidable\Uuidable; class User extends Model { use Uuidable; ... /** * Name of the field to to store the UUID * * @var string */ const UUID = 'diuu'; }
用法
Fls\Uuidable\Uuidable 特性为您的模型添加了多个方法
Uuidable::findByUuid
类似于 find($key),findByUuid($uuid) 将定位第一个 Uuidable 模型,其中字段的值与参数匹配。
$user = User::findByUuid(string $uuid);
您还可以将一个数组作为第二个参数传递,该数组表示您希望从数据库中填充的列
$user = User::findByUuid(string $uuid, ['email', 'password']);
在底层,该方法依赖于 whereUuid()
Uuidable::whereUuid()
通过 uuid 值限制模型范围。您可以使用字符串值、数组或传递 Arrayable 类。**注意**:如果您传递 Eloquent 集合,它将被解析为其模型键,这些键将被作为限制参数传递。
$builder = User::whereUuid(string $uuid);
或者
$builder = User::whereUuid([$uuid]);
或者
$builder = User::whereUuid(collect([$uuid]));
或者
$builder = User::whereUuid(Users::pluck('uuid'));
变更日志
请参阅 CHANGELOG 了解最近更改的更多信息。
测试
$ composer test
贡献
请参阅 CONTRIBUTING 和 CODE_OF_CONDUCT 了解详细信息。
安全性
如果您发现任何与安全性相关的问题,请通过电子邮件 support@frictionlesssolutions.com 而不是使用问题跟踪器。
鸣谢
许可证
MIT 许可证 (MIT)。请参阅 许可证文件 了解更多信息。
