2017-07-11 08:06:06 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
2019-07-16 03:44:31 +08:00
|
|
|
use App\Contracts\Model;
|
2022-03-14 23:45:18 +08:00
|
|
|
use Illuminate\Database\Eloquent\Casts\Attribute;
|
2018-03-20 09:50:40 +08:00
|
|
|
|
2017-07-11 08:06:06 +08:00
|
|
|
/**
|
2018-03-21 02:06:06 +08:00
|
|
|
* Class FlightFieldValue
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
2018-03-21 02:47:47 +08:00
|
|
|
* @property string flight_id
|
|
|
|
* @property string name
|
|
|
|
* @property string value
|
2017-07-11 08:06:06 +08:00
|
|
|
*/
|
2018-03-21 02:06:06 +08:00
|
|
|
class FlightFieldValue extends Model
|
2017-07-11 08:06:06 +08:00
|
|
|
{
|
2018-03-21 02:06:06 +08:00
|
|
|
public $table = 'flight_field_values';
|
2017-07-11 08:06:06 +08:00
|
|
|
|
2018-03-21 08:40:19 +08:00
|
|
|
protected $fillable = [
|
2018-01-04 12:04:51 +08:00
|
|
|
'flight_id',
|
|
|
|
'name',
|
2018-05-31 03:00:20 +08:00
|
|
|
'slug',
|
2018-01-04 12:04:51 +08:00
|
|
|
'value',
|
|
|
|
];
|
2017-07-11 08:06:06 +08:00
|
|
|
|
|
|
|
public static $rules = [];
|
|
|
|
|
2018-05-31 03:00:20 +08:00
|
|
|
/**
|
2022-03-14 23:45:18 +08:00
|
|
|
* When setting the name attribute, also set the slug
|
|
|
|
*
|
|
|
|
* @return Attribute
|
2018-05-31 03:00:20 +08:00
|
|
|
*/
|
2022-03-14 23:45:18 +08:00
|
|
|
public function name(): Attribute
|
2018-05-31 03:00:20 +08:00
|
|
|
{
|
2022-03-14 23:45:18 +08:00
|
|
|
return Attribute::make(
|
|
|
|
set: fn ($name) => [
|
|
|
|
'name' => $name,
|
|
|
|
'slug' => str_slug($name),
|
|
|
|
]
|
|
|
|
);
|
2018-05-31 03:00:20 +08:00
|
|
|
}
|
|
|
|
|
2017-07-11 08:06:06 +08:00
|
|
|
/**
|
|
|
|
* Relationships
|
|
|
|
*/
|
|
|
|
public function flight()
|
|
|
|
{
|
2018-01-08 23:22:12 +08:00
|
|
|
return $this->belongsTo(Flight::class, 'flight_id');
|
2017-07-11 08:06:06 +08:00
|
|
|
}
|
|
|
|
}
|