Add additional settings; Use pilot id length from setting
This commit is contained in:
@@ -4,7 +4,7 @@ namespace App\Models;
|
||||
|
||||
use Eloquent as Model;
|
||||
|
||||
use App\Models\Traits\Uuids;
|
||||
use App\Models\Traits\HashId;
|
||||
|
||||
/**
|
||||
* Class Flight
|
||||
@@ -13,7 +13,7 @@ use App\Models\Traits\Uuids;
|
||||
*/
|
||||
class Flight extends Model
|
||||
{
|
||||
use Uuids;
|
||||
use HashId;
|
||||
|
||||
public $table = 'flights';
|
||||
public $incrementing = false;
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
namespace App\Models;
|
||||
|
||||
use Eloquent as Model;
|
||||
use App\Models\Traits\Uuids;
|
||||
use App\Models\Traits\HashId;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
/**
|
||||
@@ -13,7 +13,7 @@ use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
*/
|
||||
class Pirep extends Model
|
||||
{
|
||||
use Uuids;
|
||||
use HashId;
|
||||
use SoftDeletes;
|
||||
|
||||
public $table = 'pireps';
|
||||
|
||||
@@ -5,21 +5,21 @@ namespace App\Models\Traits;
|
||||
use Hashids\Hashids;
|
||||
|
||||
|
||||
trait Uuids
|
||||
trait HashId
|
||||
{
|
||||
protected static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
static::creating(function ($model) {
|
||||
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;
|
||||
}
|
||||
});
|
||||
@@ -73,19 +73,16 @@ class User extends Authenticatable
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $hidden
|
||||
= [
|
||||
'password',
|
||||
'remember_token',
|
||||
];
|
||||
protected $hidden = [
|
||||
'password',
|
||||
'remember_token',
|
||||
];
|
||||
|
||||
protected $casts
|
||||
= [
|
||||
'flights' => 'integer',
|
||||
'flight_time' => 'integer',
|
||||
'balance' => 'double',
|
||||
'timezone' => 'integer',
|
||||
];
|
||||
protected $casts = [
|
||||
'flights' => 'integer',
|
||||
'flight_time' => 'integer',
|
||||
'balance' => 'double',
|
||||
];
|
||||
|
||||
/**
|
||||
* Validation rules
|
||||
@@ -106,9 +103,10 @@ class User extends Authenticatable
|
||||
return $key;
|
||||
}
|
||||
|
||||
public function pilot_id()
|
||||
public function getPilotIdAttribute($value)
|
||||
{
|
||||
return $this->airline->icao.str_pad($this->id, 3, '0', STR_PAD_LEFT);
|
||||
$length = setting('pilots.id_length');
|
||||
return $this->airline->icao . str_pad($this->id, $length, '0', STR_PAD_LEFT);
|
||||
}
|
||||
|
||||
public function gravatar()
|
||||
|
||||
Reference in New Issue
Block a user