amirkacem / model-key-factory
一个用于生成 Eloquent 模型键的简单包
v1.0.1
2022-04-08 23:17 UTC
Requires
- php: ^8.0
- illuminate/contracts: ^9.0
- spatie/laravel-package-tools: ^1.4.3
Requires (Dev)
- nunomaduro/collision: ^6.1
- orchestra/testbench: ^7.3
- phpunit/phpunit: ^9.5
README
安装
composer require amirkacem/model-key-factory
您可以使用以下命令发布配置文件
php artisan vendor:publish --provider="Eloquent\KeyFactory\KeyFactoryServiceProvider" --tag="model-key-factory-config"
这是已发布配置文件的内容
return [ 'key' => [ 'length' => 20, ] ];
使用方法
这是一个非常简单的包,用于生成键。有三种方法可以生成键
使用 Key Factory
$key = \Eloquent\KeyFactory\KeyFactory::generate( prefix: 'tests', // what you want to prefix your keys with. length: 20, // optional - the default of 20 is set in the config. );
使用 Str 辅助函数
$key = \Illuminate\Support\Str::key( prefix: 'tests', // what you want to prefix your keys with. length: 20, // optional - the default of 20 is set in the config. );
测试
vendor/bin/phpunit
Eloquent 集成
有一个名为 HasKey 的 eloquent 模型特质可供使用,它将
当您创建 eloquent 模型时,特质将被启动。它将获取模型名称的前三个字符,将它们转换为小写,并附加一个 "_",然后使用它作为 Key Factory 的前缀