Add additional settings; Use pilot id length from setting

This commit is contained in:
Nabeel Shahzad
2017-12-12 12:43:58 -06:00
parent 695900a008
commit e05976a982
12 changed files with 82 additions and 45 deletions

View 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;
}
});
}
}