close

Laravel validation rules if field empty another field required

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error Laravel validation rules if field empty another field required in php. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How Laravel validation rules if field empty another field required Error Occurs?

Today I get the following error Laravel validation rules if field empty another field required in php.

How To Solve Laravel validation rules if field empty another field required Error ?

  1. How To Solve Laravel validation rules if field empty another field required Error ?

    To Solve Laravel validation rules if field empty another field required Error For new laravel versions, if you need to use required_if, it requires at least two parameters, so you should use the second and third parameter as if conditions.

  2. Laravel validation rules if field empty another field required

    To Solve Laravel validation rules if field empty another field required Error For new laravel versions, if you need to use required_if, it requires at least two parameters, so you should use the second and third parameter as if conditions.

Solution 1

You can work with two rules

'image' => 'required_if:old_image'

Or:

'image' => 'required_without:old_image'

Solution 2

For new laravel versions, if you need to use required_if, it requires at least two parameters, so you should use the second and third parameter as if conditions.

  'old_image'=>'required_if:image,=,null',
  'image'=>'required_if:old_image,=,null'

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read

Leave a Comment