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

View File

@@ -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;
}
}

View File

@@ -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;
}
}

View File

@@ -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',
];

View File

@@ -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;
});

View File

@@ -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',

View File

@@ -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',
];

View File

@@ -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');
}
}

View File

@@ -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');