I’m trying to build an application in Laravel
where I need to take input user’s job experience with their start date and end date. There is a use case where the user can be currently working in any organization, so there will not be any end_date
. I need to skip end_date
in case there is no input or check currently_working
checkbox (trying Boolean value) validate the user inputs, my validation rule look something like this:
public function rules()
{
return [
'employeee_type'=>'required',
'company_name'=>'required',
'location' =>'required',
'start_date' => 'required|date|before:end_date',
'end_date'=> Rule::excludeIf(fn () => request('currently_working')).'sometimes|date|after:start_date',
];
}
Even though I’m passing empty value to end_date
with currently_working
as false, I’m getting error
0: "The end date is not a valid date."
1: "The end date must be a date after start date."
How can I fix this, any help is appreciated. Thanks
2
Answers
You can use "required_if" validation and add "currently_working" in your request
link to laravel doc here