check(); } /** * Prepare the data for validation. * * @return void */ protected function prepareForValidation() { /** @var \App\Models\User|null */ $user = auth()->user(); if ($user) { if (!$user->isAdmin()) { $this->merge([ 'status' => $this->site->status->value, 'is_internal' => false, ]); } else { $this->merge([ 'is_internal' => $this->is_internal ? true : false, ]); } } } /** * Get the validation rules that apply to the request. * * @return array */ public function rules() { return [ 'site_id' => [ 'required', 'exists:sites,id', // @phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed function ($attribute, $value, $fail) { /** @var \App\Models\User */ $user = auth()->user(); if ($user->isAdmin()) { return; } if (!in_array($value, $user->sites()->pluck('id')->all())) { $fail(__('Veuillez choisir entre :values', [ 'values' => $user->sites()->pluck('name')->implode(',') ])); } } ], 'type' => [ 'required', // @phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed function ($attribute, $value, $fail) { if (!in_array($value, TicketType::toValues())) { $fail(__('Veuillez choisir entre :values', [ 'value' => implode(',', TicketType::toLabels()) ])); } } ], 'status' => [ 'required', // @phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed function ($attribute, $value, $fail) { if (!in_array($value, TicketStatus::toValues())) { $fail(__('Veuillez choisir entre :values', [ 'value' => implode(',', TicketStatus::toLabels()) ])); } } ], 'text' => 'required|string|min:40', 'file_ticket' => 'mimes:jpeg,jpg,png,pdf|max:2048', 'file_ticket2' => 'mimes:jpeg,jpg,png,pdf|max:2048', 'is_internal' => 'required|boolean' ]; } }