Answer the question
In order to leave comments, you need to log in
How can I add a Rule to the validator so that the rule fires after the main validation?
Good afternoon. Given:
The form for creating a booking for visiting a massage
The form has 3 fields - time_from, time_to, massage_cabinet
The controller has the following code:
public function validation()
{
$request_data = request()->only(['meet_room_id', 'time_from', 'time_to', 'date']);
$validation1 = Validator::make($request_data, [
'time_from'=>['required','date_format:H:i'],
'time_to'=>'required|date_format:H:i|after:time_from',
'meet_room_id'=>["required","exists:meet_rooms,id", new BookingCalendarRule($request_data)]
]);
}
Answer the question
In order to leave comments, you need to log in
There is a rule called bail. Add it to each field and the validator will fall as soon as at least one check is not passed, which means that the queue will not reach your custom rule.
Plus, you don’t need to pass any requests to the custom rule - everything that is needed is passed to the passes() method of the rule:
You pass only the name of some additional field to the rule constructor - of the time_from type.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question