Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

field validation for other field is not null

I have 2 fields price and currency.I want to make dependency validation if price!=null currency field is required and if currency!=null price field is required as well as I want to check price field is numeric. if both field is null and that both field is not required.I want to validate in laravel 5.3

$this->validate($request,[
  'price'=>'numeric',
  'price'=>'required_if:currency,nullable',
  'currency'=>'required_if:price,not nullable',
]);
like image 535
user3386779 Avatar asked Nov 03 '17 09:11

user3386779


People also ask

How do you check if a field is NULL in validation rule?

The Validation Rule contains ISNULL(TEXT(Picklist_Field__c)). ISNULL determines if an expression is null (blank) and returns TRUE if it is. If it contains a value, this function returns FALSE.

What is field validation?

Field validation is an automated process of ascertaining that each field contains the correct value before the form is accepted. The concept is straightforward.


1 Answers

You can use required_with for this.

$this->validate($request,[
  'price'=>'required_with:currency|numeric',
  'currency'=>'required_with:price',
]);
like image 66
Pawan Kumar Avatar answered Oct 11 '22 17:10

Pawan Kumar