phpvms/app/Http/Requests/UpdatePirepRequest.php

47 lines
1.3 KiB
PHP
Raw Normal View History

2017-06-29 08:54:05 +08:00
<?php
namespace App\Http\Requests;
use App\Contracts\FormRequest;
2017-06-29 08:54:05 +08:00
use App\Models\Pirep;
2018-05-30 00:04:28 +08:00
use App\Repositories\PirepFieldRepository;
use Illuminate\Support\Facades\Log;
2017-06-29 08:54:05 +08:00
2017-07-05 02:57:08 +08:00
class UpdatePirepRequest extends FormRequest
2017-06-29 08:54:05 +08:00
{
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules(): array
2017-06-29 08:54:05 +08:00
{
2018-05-30 00:04:28 +08:00
// Don't run validations if it's just being saved
$action = strtolower(request('submit', 'submit'));
if ($action === 'save' || $action === 'cancel' || $action === 'delete') {
return [
'airline_id' => 'required|exists:airlines,id',
'flight_number' => 'required',
'dpt_airport_id' => 'required',
'arr_airport_id' => 'required',
];
}
$field_rules = Pirep::$rules;
2019-08-02 01:15:33 +08:00
$field_rules['hours'] = 'required|integer';
$field_rules['minutes'] = 'required|integer';
2018-05-30 00:04:28 +08:00
2018-08-27 00:40:04 +08:00
// Add the validation rules for the custom fields
2018-05-30 00:04:28 +08:00
$pirepFieldRepo = app(PirepFieldRepository::class);
$custom_fields = $pirepFieldRepo->all();
foreach ($custom_fields as $field) {
Log::info('field:', $field->toArray());
$field_rules[$field->slug] = $field->required ? 'required' : 'nullable';
}
return $field_rules;
2017-06-29 08:54:05 +08:00
}
}