Save PIREP route to ACARS data table #102
This commit is contained in:
@@ -7,19 +7,27 @@ use Hashids\Hashids;
|
||||
|
||||
trait HashId
|
||||
{
|
||||
/**
|
||||
* @return string
|
||||
* @throws \Hashids\HashidsException
|
||||
*/
|
||||
protected static function createNewHashId()
|
||||
{
|
||||
$hashids = new Hashids('', 12);
|
||||
$mt = str_replace('.', '', microtime(true));
|
||||
return $hashids->encode($mt);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register callbacks
|
||||
*/
|
||||
protected static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
static::creating(function ($model)
|
||||
{
|
||||
static::creating(function ($model) {
|
||||
$key = $model->getKeyName();
|
||||
|
||||
if (empty($model->{$key})) {
|
||||
$hashids = new Hashids('', 12);
|
||||
$mt = str_replace('.', '', microtime(true));
|
||||
$id = $hashids->encode($mt);
|
||||
|
||||
$id = static::createNewHashId();
|
||||
$model->{$key} = $id;
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user