1e320835c2
* fix map-info-box display * Check user on PIREP show/edit/update/submit * add missing use * refactoring according to comments; use UpdatePirepRequest for authorization and make user available to view Co-authored-by: Andreas Palm <ap@ewsp.de> Co-authored-by: Nabeel S <nabeelio@users.noreply.github.com>
57 lines
1.6 KiB
PHP
57 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
use App\Contracts\FormRequest;
|
|
use App\Models\Pirep;
|
|
use App\Repositories\PirepFieldRepository;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
class UpdatePirepRequest extends FormRequest
|
|
{
|
|
/**
|
|
* Is the user allowed to do this?
|
|
*/
|
|
public function authorize(): bool
|
|
{
|
|
$pirep = Pirep::findOrFail($this->route('id'), ['user_id']);
|
|
return $pirep->user_id === Auth::id();
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
// 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;
|
|
|
|
$field_rules['hours'] = 'required|integer';
|
|
$field_rules['minutes'] = 'required|integer';
|
|
|
|
// Add the validation rules for the custom fields
|
|
$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;
|
|
}
|
|
}
|