check(); } /** * Prepare the data for validation. * * @return void * * @throws ValidationException When prepare merge fails to parse dates. */ protected function prepareForValidation() { try { $this->merge([ 'date_start' => Carbon::parse("$this->date_start_date $this->date_start_time:00")->toDateTimeString(), 'date_end' => Carbon::parse("$this->date_end_date $this->date_end_time:00")->toDateTimeString(), 'on_top' => $this->on_top ? true : false, ]); } catch (InvalidFormatException $e) { $error = ValidationException::withMessages([ 'date_start_date' => ['Format de date incorrect'], 'date_end_date' => ['Format de date incorrect'], ]); throw $error; } } /** * Get the validation rules that apply to the request. * * @return array */ public function rules() { return [ 'picture_news' => 'required|image|mimes:jpeg,png,jpg|max:1024|dimensions:max_width=380,max_height=298', 'alt_text_picture_news' => 'required|max:255', 'title' => 'required|max:255', 'text' => 'required|min:20', 'date_start' => [ 'required', 'date_format:Y-m-d H:i:s', 'before:' . Carbon::now()->parse('2037-12-31') ], 'date_end' => [ 'required', 'date_format:Y-m-d H:i:s', 'after:date_start', 'before:' . Carbon::now()->parse('2037-12-31') ], 'picture_home' => 'required|image|mimes:jpeg,png,jpg|max:2048|dimensions:max_width=1030,max_height=239', 'alt_text_picture_home' => 'required|max:255', 'on_top' => 'nullable|boolean', ]; } }