check(); } /** * Get the validation rules that apply to the request. * * @return array * @throws \Illuminate\Validation\ValidationException If given dates are unparsable of period * is bigger than 1 year. * @throws \Exception If carbon date processing failed. */ public function rules() { if ($this->post()) { try { if ((Carbon::parse($this->end)->diffInDays(Carbon::parse($this->start)) + 1) > 365) { throw ValidationException::withMessages([ 'Vous devez sélectionner une période de maximum 1 ans' ]); } } catch (Exception $e) { if (\get_class($e) !== ValidationException::class) { throw ValidationException::withMessages([ 'Les dates séléectionnées ne sembles pas être valides' ]); } throw $e; } return [ 'question' => 'required|exists:questions,id', 'start' => 'required|date|date_format:Y-m-d', 'end' => 'required|date|date_format:Y-m-d|after_or_equal:start', ]; } //end if return []; } }