request->set('per_day', 2); $this->request->set('date_time', 1); $this->request->set('next_vihar', 1); return parent::getValidatorInstance(); } /** * Get the validation rules that apply to the request. * * @return array */ public function rules(Request $request) { $array = [ 'sant_id' => 'exists:sants,id', 'from' => 'required', 'to' => 'required', 'start_date' => 'required|date_format:Y-m-d', 'start_time' => 'date_format:H:i', // 'end_date' => 'required|date_format:Y-m-d|after_or_equal:start_date', 'per_day' => [new ViharStorePerDay($request->all())], 'date_time' => [new ViharDoesNotStoreForSameDateTime($request->all())], 'next_vihar' => [new ViharCanNotAfterTwoHours($request->all())], ]; $startDate = Carbon::createFromFormat('Y-m-d H:i:s', $request->start_date .' '. '00:00:00'); $todayDate = Carbon::createFromFormat('Y-m-d H:i:s', Carbon::now()->format('Y-m-d') .' '. '00:00:00'); $result = $todayDate->eq($startDate); if ($result) { $array['start_time'] = 'date_format:H:i|after:'.Carbon::now()->format('H:i'); } return $array; } protected function failedValidation(Validator $validator) { if (Request::wantsJson()) { throw new HttpResponseException(response()->json(['message' => $validator->errors()->first(), 'error' => true, 'status' => 422], 422)); } else { throw new ValidationException($validator); } } /** * Get the validation rules that apply to the request. * * @return array */ public function messages() { return [ 'start_time.after' => 'Please enter a time after the current time.', ]; } }