2017-06-29 08:54:05 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
|
2018-01-24 05:48:30 +08:00
|
|
|
use Log;
|
2017-07-05 02:57:08 +08:00
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
2017-06-29 08:54:05 +08:00
|
|
|
|
2018-01-24 05:48:30 +08:00
|
|
|
use App\Models\Pirep;
|
|
|
|
use App\Repositories\PirepFieldRepository;
|
2017-07-05 02:57:08 +08:00
|
|
|
|
|
|
|
class CreatePirepRequest extends FormRequest
|
2017-06-29 08:54:05 +08:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* 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()
|
|
|
|
{
|
2018-01-24 05:48:30 +08:00
|
|
|
$field_rules = Pirep::$rules;
|
|
|
|
|
|
|
|
$field_rules['hours'] = 'nullable|integer';
|
2018-02-07 00:02:34 +08:00
|
|
|
$field_rules['minutes'] = 'nullable|integer';
|
2018-01-24 05:48:30 +08:00
|
|
|
|
|
|
|
# Add the validation rules for the custom fields
|
|
|
|
$pirepFieldRepo = app(PirepFieldRepository::class);
|
|
|
|
|
|
|
|
$custom_fields = $pirepFieldRepo->all();
|
|
|
|
foreach ($custom_fields as $field) {
|
2018-02-07 00:02:34 +08:00
|
|
|
Log::info('field:', $field->toArray());
|
2018-01-24 05:48:30 +08:00
|
|
|
$field_rules[$field->slug] = $field->required ? 'required' : 'nullable';
|
|
|
|
}
|
|
|
|
|
|
|
|
Log::debug('createPirepFormRequest::rules', $field_rules);
|
|
|
|
|
|
|
|
return $field_rules;
|
2017-06-29 08:54:05 +08:00
|
|
|
}
|
|
|
|
}
|