Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's is the difference between required_with and required_with_all laravel validation

I already tried have a look at https://laravel.com/docs/5.4/validation but still , i don't really get what's is the difference between :

required_with_all

and

required_without


Anyone can explain to me in detail what's the difference ?

like image 680
Bathulah Mahir Avatar asked Jun 20 '17 04:06

Bathulah Mahir


2 Answers

required_with_all :

Laravel Doc: The field under validation must be present only if all of the other specified fields are present.

required_without_all :

Laravel Doc: The field under validation must be present and not empty only when all of the other specified fields are not present.

Example:

$rules = array(
    'facebook_id' => 'required_without_all:twitter_id,instagram_id',
    'twitter_id' => 'required_without_all:facebook_id,instagram_id',
    'instagram_id' => 'required_without_all:facebook_id,twitter_id',
);
$validator = Validator::make(Input::all(), $rules);

required_with:

Laravel Doc: The field under validation must be present only if any of the other specified fields are present.

Example:

$rules = array(
'sell' => 'required_without:rent',
'rent' => 'required_without:sell',
'price' => 'required_with:sell|numeric|min:0',
);
like image 83
RïshïKêsh Kümar Avatar answered Sep 28 '22 05:09

RïshïKêsh Kümar


required_with:

The field under validation must be present and not empty only if any of the other specified fields are present.

required_with_all:

The field under validation must be present and not empty only if all of the other specified fields are present.

Note: Check bold text above.

For more detail see Laravel docs

like image 26
Govind Samrow Avatar answered Sep 28 '22 05:09

Govind Samrow