check(); } /** * Prepare the data for validation. * * @return void */ protected function prepareForValidation() { $this->merge([ 'status' => $this->status ? true : false ]); if (Document::query()->where('id', $this->document_id)->exists()) { $this->merge([ 'directory_id' => Document::query()->where('id', $this->document_id) ->value('directory_id') ]); } } /** * Get the validation rules that apply to the request. * * @return array */ public function rules() { return [ 'directory_id' => 'required|integer', 'document_id' => 'sometimes:directory_id|nullable|integer', 'title' => 'required|min:3|max:255', 'type' => 'required|min:3|max:255', 'path' => 'required|min:3|max:255', 'lang' => [ 'required', new EnumIsValidRule(LangEnum::class) ], 'status' => 'required|boolean' ]; } /** * Get custom attributes for validator errors. * * @return array */ public function attributes() { return [ 'directory_id' => \trans('dossier à associer'), 'document_id' => \trans('document (FR) à associer'), 'title' => \trans('titre'), 'uuid' => \trans('document'), 'type' => \trans('type du document'), 'path' => \trans('chemin du document'), 'lang' => \trans('langue du document'), 'status' => \trans('état de publication du document'), ]; } }