Hello Dev’s Now In this artical, i will give you a short and simple example of laravel in validation required when another field is empty.
So we know that laravel provide us several in-built laravel validation required_without . If we need to add validation rules like required when another other field is empty in laravel then we can do it by using required_without.
So now I am going to explain with you, If we can not enter test (field) value at that time test1 (field) is required. So at that time we can add validation required_without.
So, you can use this way:
"test1" =>"required_without:test"
Example:
public function store(Request $request) { $request->validate([ "test" =>"required", "test1" =>"required_without:test" ]); dd("Done!"); }
It return validation error otherwise it show Done!.
Read Also : How To Get Current Page Url in Jquery ?