cleanup validation rules

This commit is contained in:
Nabeel Shahzad
2017-12-30 14:37:10 -06:00
parent 4bf3541e25
commit 7180bfb111
8 changed files with 32 additions and 64 deletions
+4 -12
View File
@@ -7,24 +7,16 @@ use App\Models\Airline;
class CreateAirlineRequest extends FormRequest class CreateAirlineRequest extends FormRequest
{ {
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize() public function authorize()
{ {
return true; return true;
} }
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules() public function rules()
{ {
return Airline::$rules; $rules = Airline::$rules;
$rules['iata'] .= '|unique:airlines';
$rules['icao'] .= '|unique:airlines';
return $rules;
} }
} }
+3 -12
View File
@@ -7,24 +7,15 @@ use Illuminate\Foundation\Http\FormRequest;
class CreateAirportRequest extends FormRequest class CreateAirportRequest extends FormRequest
{ {
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize() public function authorize()
{ {
return true; return true;
} }
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules() public function rules()
{ {
return Airport::$rules; $rules = Airport::$rules;
$rules['icao'] .= '|unique:airports';
return $rules;
} }
} }
+2 -1
View File
@@ -34,7 +34,8 @@ class Airline extends BaseModel
* @var array * @var array
*/ */
public static $rules = [ public static $rules = [
'code' => 'required|max:3|unique:airlines', 'iata' => 'required|max:5',
'icao' => 'required|max:5',
'name' => 'required', 'name' => 'required',
]; ];
+11 -1
View File
@@ -14,11 +14,13 @@ class Airport extends BaseModel
public $fillable = [ public $fillable = [
'id', 'id',
'iata',
'icao', 'icao',
'name', 'name',
'location', 'location',
'lat', 'lat',
'lon', 'lon',
'hub',
'timezone', 'timezone',
'fuel_100ll_cost', 'fuel_100ll_cost',
'fuel_jeta_cost', 'fuel_jeta_cost',
@@ -28,6 +30,7 @@ class Airport extends BaseModel
protected $casts = [ protected $casts = [
'lat' => 'float', 'lat' => 'float',
'lon' => 'float', 'lon' => 'float',
'hub' => 'boolean',
'fuel_100ll_cost' => 'float', 'fuel_100ll_cost' => 'float',
'fuel_jeta_cost' => 'float', 'fuel_jeta_cost' => 'float',
'fuel_mogas_cost' => 'float', 'fuel_mogas_cost' => 'float',
@@ -39,7 +42,10 @@ class Airport extends BaseModel
* @var array * @var array
*/ */
public static $rules = [ 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 * Make sure the ID is set to the ICAO
*/ */
static::creating(function (Airport $model) { static::creating(function (Airport $model) {
if(!empty($model->iata)) {
$model->iata = strtoupper($model->iata);
}
$model->icao = strtoupper($model->icao); $model->icao = strtoupper($model->icao);
$model->id = $model->icao; $model->id = $model->icao;
}); });
-10
View File
@@ -29,11 +29,6 @@ class Flight extends BaseModel
'active', 'active',
]; ];
/**
* The attributes that should be casted to native types.
*
* @var array
*/
protected $casts = [ protected $casts = [
'flight_number' => 'integer', 'flight_number' => 'integer',
'route_code' => 'string', 'route_code' => 'string',
@@ -46,11 +41,6 @@ class Flight extends BaseModel
'active' => 'boolean', 'active' => 'boolean',
]; ];
/**
* Validation rules
*
* @var array
*/
public static $rules = [ public static $rules = [
'flight_number' => 'required', 'flight_number' => 'required',
'dpt_airport_id' => 'required', 'dpt_airport_id' => 'required',
+1 -10
View File
@@ -43,11 +43,6 @@ class Pirep extends BaseModel
'raw_data', 'raw_data',
]; ];
/**
* The attributes that should be casted to native types.
*
* @var array
*/
protected $casts = [ protected $casts = [
'id' => 'string', 'id' => 'string',
'flight_time' => 'integer', 'flight_time' => 'integer',
@@ -61,12 +56,8 @@ class Pirep extends BaseModel
'status' => 'integer', 'status' => 'integer',
]; ];
/**
* Validation rules
*
* @var array
*/
public static $rules = [ public static $rules = [
'flight_number' => 'required',
'dpt_airport_id' => 'required', 'dpt_airport_id' => 'required',
'arr_airport_id' => 'required', 'arr_airport_id' => 'required',
]; ];
+6 -18
View File
@@ -19,33 +19,21 @@ class Rank extends BaseModel
'auto_promote' 'auto_promote'
]; ];
/**
* The attributes that should be casted to native types.
*
* @var array
*/
protected $casts = [ protected $casts = [
'name' => 'string', 'name' => 'string',
'hours' => 'integer', 'hours' => 'integer',
'auto_approve_acars' => 'bool', 'auto_approve_acars' => 'bool',
'auto_approve_manual' => 'bool', 'auto_approve_manual' => 'bool',
'auto_promote' => 'bool', 'auto_promote' => 'bool',
]; ];
/**
* Validation rules
*
* @var array
*/
public static $rules = [ public static $rules = [
'name' => 'required|unique:ranks', 'name' => 'required|unique:ranks',
'hours' => 'required', 'hours' => 'required',
]; ];
public function subfleets() { public function subfleets() {
return $this->belongsToMany( return $this->belongsToMany('App\Models\Subfleet', 'subfleet_rank')
'App\Models\Subfleet', ->withPivot('acars_pay', 'manual_pay');
'subfleet_rank'
)->withPivot('acars_pay', 'manual_pay');
} }
} }
+5
View File
@@ -31,6 +31,11 @@ class Subfleet extends BaseModel
'gross_weight' => 'double', 'gross_weight' => 'double',
]; ];
public static $rules = [
'name' => 'required',
'type' => 'required',
];
public function aircraft() public function aircraft()
{ {
return $this->hasMany('App\Models\Aircraft', 'subfleet_id'); return $this->hasMany('App\Models\Aircraft', 'subfleet_id');