phpvms/app/Models/Airline.php

84 lines
1.6 KiB
PHP
Raw Normal View History

2017-06-09 09:02:52 +08:00
<?php
namespace App\Models;
use App\Models\Enums\JournalType;
use App\Models\Traits\JournalTrait;
2017-06-09 09:02:52 +08:00
/**
2017-06-20 00:50:25 +08:00
* Class Airline
2018-03-03 07:29:11 +08:00
* @property Journal journal
2017-06-09 09:02:52 +08:00
* @package App\Models
*/
class Airline extends BaseModel
2017-06-09 09:02:52 +08:00
{
use JournalTrait;
2017-06-09 09:02:52 +08:00
public $table = 'airlines';
/**
* The journal type for the callback
*/
public $journal_type = JournalType::AIRLINE;
2017-06-09 09:02:52 +08:00
public $fillable = [
2017-08-16 21:11:39 +08:00
'icao',
2017-07-23 12:03:39 +08:00
'iata',
2017-06-09 09:02:52 +08:00
'name',
2017-08-16 21:11:39 +08:00
'logo',
'country',
'total_flights',
'total_time',
2017-07-08 21:09:58 +08:00
'active',
2017-06-09 09:02:52 +08:00
];
/**
* The attributes that should be casted to native types.
*
* @var array
*/
protected $casts = [
'total_flights' => 'int',
'total_time' => 'int',
'active' => 'boolean',
2017-06-09 09:02:52 +08:00
];
/**
* Validation rules
*
* @var array
*/
public static $rules = [
2018-01-01 04:20:52 +08:00
'country' => 'nullable',
'iata' => 'nullable|max:5',
'icao' => 'required|max:5',
'logo' => 'nullable',
'name' => 'required',
2017-06-09 09:02:52 +08:00
];
2017-08-16 21:11:39 +08:00
/**
* For backwards compatibility
*/
public function getCodeAttribute() {
return $this->icao;
}
2018-01-01 04:20:52 +08:00
protected static function boot()
{
parent::boot();
/**
* IATA and ICAO should be in all caps
*/
static::creating(function (Airline $model) {
if (!empty($model->iata)) {
$model->iata = strtoupper($model->iata);
}
if (!empty($model->icao)) {
$model->icao = strtoupper($model->icao);
}
});
}
2017-06-09 09:02:52 +08:00
}