Laravel validation required if another field is empty

Share Me
  •  
  •  
  •  
  • 1
  •  
  •  
  •  
  •  
  •  
  •  
  •  
    1
    Share

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 ?

Thanks for read. I hope it help you. For more you can follow us onĀ facebook

About code chef

My name is Shahriar sagor. I'm a developer. I live in Bangladesh and I love to write tutorials and tips that will help to other Developer's. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by code chef →