2017-06-29 08:54:05 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
2019-07-16 03:44:31 +08:00
|
|
|
use App\Contracts\Model;
|
2018-07-13 10:20:10 +08:00
|
|
|
use App\Models\Enums\PirepFieldSource;
|
2018-03-20 09:50:40 +08:00
|
|
|
|
2017-06-29 08:54:05 +08:00
|
|
|
/**
|
2018-07-13 10:20:10 +08:00
|
|
|
* Class PirepFieldValue
|
2017-06-29 08:54:05 +08:00
|
|
|
*/
|
2018-07-13 10:20:10 +08:00
|
|
|
class PirepFieldValue extends Model
|
2017-06-29 08:54:05 +08:00
|
|
|
{
|
|
|
|
public $table = 'pirep_field_values';
|
|
|
|
|
2018-03-21 08:40:19 +08:00
|
|
|
protected $fillable = [
|
2018-01-04 12:04:51 +08:00
|
|
|
'pirep_id',
|
|
|
|
'name',
|
2018-05-31 03:00:20 +08:00
|
|
|
'slug',
|
2018-01-04 12:04:51 +08:00
|
|
|
'value',
|
|
|
|
'source',
|
|
|
|
];
|
2017-06-29 08:54:05 +08:00
|
|
|
|
2018-01-04 12:04:51 +08:00
|
|
|
public static $rules = [
|
|
|
|
'name' => 'required',
|
|
|
|
];
|
2017-06-30 04:50:16 +08:00
|
|
|
|
2018-07-13 10:20:10 +08:00
|
|
|
protected $casts = [
|
|
|
|
'source' => 'integer',
|
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If it was filled in from ACARS, then it's read only
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
2018-07-13 10:20:10 +08:00
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function getReadOnlyAttribute()
|
|
|
|
{
|
|
|
|
return $this->source === PirepFieldSource::ACARS;
|
|
|
|
}
|
|
|
|
|
2018-05-31 03:00:20 +08:00
|
|
|
/**
|
|
|
|
* @param $name
|
|
|
|
*/
|
|
|
|
public function setNameAttribute($name): void
|
|
|
|
{
|
|
|
|
$this->attributes['name'] = $name;
|
|
|
|
$this->attributes['slug'] = str_slug($name);
|
|
|
|
}
|
|
|
|
|
2017-06-30 04:50:16 +08:00
|
|
|
/**
|
|
|
|
* Foreign Keys
|
|
|
|
*/
|
|
|
|
public function pirep()
|
|
|
|
{
|
2018-01-08 23:22:12 +08:00
|
|
|
return $this->belongsTo(Pirep::class, 'pirep_id');
|
2017-06-30 04:50:16 +08:00
|
|
|
}
|
2017-06-29 08:54:05 +08:00
|
|
|
}
|