Add additional settings; Use pilot id length from setting
This commit is contained in:
27
app/Models/Traits/HashId.php
Normal file
27
app/Models/Traits/HashId.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Traits;
|
||||
|
||||
use Hashids\Hashids;
|
||||
|
||||
|
||||
trait HashId
|
||||
{
|
||||
protected static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
static::creating(function ($model)
|
||||
{
|
||||
$key = $model->getKeyName();
|
||||
|
||||
if (empty($model->{$key})) {
|
||||
$hashids = new Hashids('', 10);
|
||||
$mt = str_replace('.', '', microtime(true));
|
||||
$id = $hashids->encode($mt);
|
||||
|
||||
$model->{$key} = $id;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user