chistel/laravel-uniqueid
Composer 安装命令:
composer require chistel/laravel-uniqueid
包简介
Generate uniqueid when saving Eloquent models to be used as auth key and route key
README 文档
README
but the difference is that it's meant to use unique string for model routes.
Installation
You can install the package via composer:
composer require chistel/laravel-uniqueid
Usage
Your Eloquent models should use the Chistel\LaravelUniqueId\HasUniqueId trait and the Chistel\LaravelUniqueId\UniqueIdOptions class.
The trait contains an abstract method getUniqueIdOptions() that you must implement yourself.
Here's an example of how to implement the trait:
<?php namespace App\Models; use Illuminate\Database\Eloquent\Model; use Chistel\LaravelUniqueId\HasUniqueId; use Chistel\LaravelUniqueId\UniqueIdOptions; class UserModel extends Model { use HasUniqueId; /** * Get the route key for the model. * * @return string */ public function getRouteKeyName() { return 'user_unique_id'; // this is the unique key column } /** * Get the options for generating model uniqueId. */ public function getUniqueIdOptions() : UniqueIdOptions { return UniqueIdOptions::create() ->saveUniqueIdTo('user_unique_id') // this is the unique key column ->uniqueIdShouldBeNoLongerThan(8); } }
the uniqueid is only available on model creating.
统计信息
- 总下载量: 426
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-05-07