diff --git a/app/Http/Requests/CreateAirlineRequest.php b/app/Http/Requests/CreateAirlineRequest.php index 0f8f3a2b..36e029fb 100644 --- a/app/Http/Requests/CreateAirlineRequest.php +++ b/app/Http/Requests/CreateAirlineRequest.php @@ -7,24 +7,16 @@ use App\Models\Airline; class CreateAirlineRequest extends FormRequest { - - /** - * Determine if the user is authorized to make this request. - * - * @return bool - */ public function authorize() { return true; } - /** - * Get the validation rules that apply to the request. - * - * @return array - */ public function rules() { - return Airline::$rules; + $rules = Airline::$rules; + $rules['iata'] .= '|unique:airlines'; + $rules['icao'] .= '|unique:airlines'; + return $rules; } } diff --git a/app/Http/Requests/CreateAirportRequest.php b/app/Http/Requests/CreateAirportRequest.php index afc640cf..52e6fa66 100644 --- a/app/Http/Requests/CreateAirportRequest.php +++ b/app/Http/Requests/CreateAirportRequest.php @@ -7,24 +7,15 @@ use Illuminate\Foundation\Http\FormRequest; class CreateAirportRequest extends FormRequest { - - /** - * Determine if the user is authorized to make this request. - * - * @return bool - */ public function authorize() { return true; } - /** - * Get the validation rules that apply to the request. - * - * @return array - */ public function rules() { - return Airport::$rules; + $rules = Airport::$rules; + $rules['icao'] .= '|unique:airports'; + return $rules; } } diff --git a/app/Models/Airline.php b/app/Models/Airline.php index 7f4e3460..34f7afd0 100644 --- a/app/Models/Airline.php +++ b/app/Models/Airline.php @@ -34,7 +34,8 @@ class Airline extends BaseModel * @var array */ public static $rules = [ - 'code' => 'required|max:3|unique:airlines', + 'iata' => 'required|max:5', + 'icao' => 'required|max:5', 'name' => 'required', ]; diff --git a/app/Models/Airport.php b/app/Models/Airport.php index 12f0b732..b4cad11e 100644 --- a/app/Models/Airport.php +++ b/app/Models/Airport.php @@ -14,11 +14,13 @@ class Airport extends BaseModel public $fillable = [ 'id', + 'iata', 'icao', 'name', 'location', 'lat', 'lon', + 'hub', 'timezone', 'fuel_100ll_cost', 'fuel_jeta_cost', @@ -28,6 +30,7 @@ class Airport extends BaseModel protected $casts = [ 'lat' => 'float', 'lon' => 'float', + 'hub' => 'boolean', 'fuel_100ll_cost' => 'float', 'fuel_jeta_cost' => 'float', 'fuel_mogas_cost' => 'float', @@ -39,7 +42,10 @@ class Airport extends BaseModel * @var array */ public static $rules = [ - #'icao' => 'required|unique:airports' + 'icao' => 'required', + 'name' => 'required', + 'lat' => 'required', + 'lon' => 'required', ]; /** @@ -54,6 +60,10 @@ class Airport extends BaseModel * Make sure the ID is set to the ICAO */ static::creating(function (Airport $model) { + if(!empty($model->iata)) { + $model->iata = strtoupper($model->iata); + } + $model->icao = strtoupper($model->icao); $model->id = $model->icao; }); diff --git a/app/Models/Flight.php b/app/Models/Flight.php index 40d76b6b..2b5089c3 100644 --- a/app/Models/Flight.php +++ b/app/Models/Flight.php @@ -29,11 +29,6 @@ class Flight extends BaseModel 'active', ]; - /** - * The attributes that should be casted to native types. - * - * @var array - */ protected $casts = [ 'flight_number' => 'integer', 'route_code' => 'string', @@ -46,11 +41,6 @@ class Flight extends BaseModel 'active' => 'boolean', ]; - /** - * Validation rules - * - * @var array - */ public static $rules = [ 'flight_number' => 'required', 'dpt_airport_id' => 'required', diff --git a/app/Models/Pirep.php b/app/Models/Pirep.php index 3f0baceb..2a2a024d 100644 --- a/app/Models/Pirep.php +++ b/app/Models/Pirep.php @@ -43,11 +43,6 @@ class Pirep extends BaseModel 'raw_data', ]; - /** - * The attributes that should be casted to native types. - * - * @var array - */ protected $casts = [ 'id' => 'string', 'flight_time' => 'integer', @@ -61,12 +56,8 @@ class Pirep extends BaseModel 'status' => 'integer', ]; - /** - * Validation rules - * - * @var array - */ public static $rules = [ + 'flight_number' => 'required', 'dpt_airport_id' => 'required', 'arr_airport_id' => 'required', ]; diff --git a/app/Models/Rank.php b/app/Models/Rank.php index 0dd02c1f..bff2040d 100644 --- a/app/Models/Rank.php +++ b/app/Models/Rank.php @@ -19,33 +19,21 @@ class Rank extends BaseModel 'auto_promote' ]; - /** - * The attributes that should be casted to native types. - * - * @var array - */ protected $casts = [ - 'name' => 'string', - 'hours' => 'integer', - 'auto_approve_acars' => 'bool', + 'name' => 'string', + 'hours' => 'integer', + 'auto_approve_acars' => 'bool', 'auto_approve_manual' => 'bool', - 'auto_promote' => 'bool', + 'auto_promote' => 'bool', ]; - /** - * Validation rules - * - * @var array - */ public static $rules = [ 'name' => 'required|unique:ranks', 'hours' => 'required', ]; public function subfleets() { - return $this->belongsToMany( - 'App\Models\Subfleet', - 'subfleet_rank' - )->withPivot('acars_pay', 'manual_pay'); + return $this->belongsToMany('App\Models\Subfleet', 'subfleet_rank') + ->withPivot('acars_pay', 'manual_pay'); } } diff --git a/app/Models/Subfleet.php b/app/Models/Subfleet.php index 340cdbe4..3e975a7c 100644 --- a/app/Models/Subfleet.php +++ b/app/Models/Subfleet.php @@ -31,6 +31,11 @@ class Subfleet extends BaseModel 'gross_weight' => 'double', ]; + public static $rules = [ + 'name' => 'required', + 'type' => 'required', + ]; + public function aircraft() { return $this->hasMany('App\Models\Aircraft', 'subfleet_id');