james322/has-nano-id-laravel
最新稳定版本:1.0.0
Composer 安装命令:
composer require james322/has-nano-id-laravel
包简介
A php trait to add nano id to laravel models.
README 文档
README
A php trait to add Nano IDs to Laravel models.
Installation
You can install the package via composer:
composer require james322/has-nano-id-laravel
Publish the config file with:
php artisan vendor:publish --tag="has-nano-id-laravel-config"
This is the contents of the published config file:
return [ 'alphabet' => env('NANO_ID_ALPHABET', '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz-'), 'size' => (int) env('NANO_ID_SIZE', 21) ];
Usage
In your model import the trait and add the column to your database table you wish to use for the Nano ID.
use james322\HasNanoId\HasNanoId; class User { use HasNanoId; }
Now when the model is created for the first time a Nano ID will be generated.
The database column used for storing the Nano ID can be customized by adding a $nano_id_key property on your model.
use james322\HasNanoId\HasNanoId; class User { use HasNanoId; public $nano_id_key = 'custom_column'; // default 'public_key' }
The default alphabet and size (length) of the nano id can be customized in the nano-id.php config file. You can also customize it on a per model basis by adding $nano_id_alphabet and $nano_id_size property to your model.
use james322\HasNanoId\HasNanoId; class User { use HasNanoId; public $nano_id_alphabet = 'abcdefg1234567890-'; // default '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz-' public $nano_id_size = 14; // default 21 }
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
License
The MIT License (MIT). Please see License File for more information.
统计信息
- 总下载量: 7
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-11-09