10-Apr-2023
.
Admin
Hello Friends,
In this tute, we will discuss laravel validation required if another field is not empty . This article will give you a simple example of laravel validation required if other field empty. If you have a question about laravel validate required if other field not empty then I will give a simple example with a solution. you'll learn laravel validation required if other field not empty . Here, Create a basic example of laravel in required_without validation.
We know laravel provide several in-built laravel validation required_without . If you need to add validation rules like required if other field is empty in laravel then you can do it using required_without.
I am going to explain you, If you can not enter test (field) value at that time test1 (field) is required. So at that time you 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!");
}
If return validation error otherwise show Done!.
It will help you...
#Laravel
#Laravel 6