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()
|
||||
|
||||
@@ -2,9 +2,11 @@
|
||||
|
||||
namespace App\Repositories;
|
||||
|
||||
use Illuminate\Support\Carbon;
|
||||
use Prettus\Repository\Contracts\CacheableInterface;
|
||||
|
||||
use App\Models\Setting;
|
||||
use App\Repositories\Traits\CacheableRepository;
|
||||
use Prettus\Repository\Contracts\CacheableInterface;
|
||||
|
||||
class SettingRepository extends BaseRepository implements CacheableInterface
|
||||
{
|
||||
@@ -16,17 +18,44 @@ class SettingRepository extends BaseRepository implements CacheableInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a setting, reading it from the cache
|
||||
* @param array $key
|
||||
* @return mixed|void
|
||||
* Get a setting, reading it from the cache possibly
|
||||
* @param string $key
|
||||
* @return mixed
|
||||
*/
|
||||
public function get($key)
|
||||
public function retrieve($key)
|
||||
{
|
||||
$key = strtolower($key);
|
||||
$setting = $this->findWhere(['key' => $key], ['type', 'value'])->first();
|
||||
|
||||
if(!$setting) {
|
||||
return null;
|
||||
}
|
||||
|
||||
# cast some types
|
||||
switch($setting->type) {
|
||||
case 'bool':
|
||||
case 'boolean':
|
||||
return (bool) $setting->value;
|
||||
break;
|
||||
case 'date':
|
||||
return Carbon::parse($setting->value);
|
||||
break;
|
||||
case 'int':
|
||||
case 'integer':
|
||||
return (int) $setting->value;
|
||||
break;
|
||||
default:
|
||||
return $setting->value;
|
||||
}
|
||||
}
|
||||
|
||||
public function set($key, $value)
|
||||
public function store($key, $value)
|
||||
{
|
||||
$setting = $this->findWhere(['key' => $key], ['id'])->first();
|
||||
if (!$setting) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$this->update(['value' => $value], $setting->id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ if (!function_exists('setting')) {
|
||||
{
|
||||
$settingRepo = app('setting');
|
||||
if($value === null) {
|
||||
return $settingRepo->get($key);
|
||||
return $settingRepo->retrieve($key);
|
||||
} else {
|
||||
$settingRepo->set($key, $value);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user