LoveCoding
LoveCoding

Reputation: 1211

Not recognizing Null value in Laravel Validation Rule with Condition

Laravel version: 7.0

I am going to validate using exists with extra condition.

My validation rule is as following:

$rule['id'] = 'required|exists:domains,id,website_id,null';

I was going to validate if id exists in domains table where website_id is null.

Even there there are some rows which meet above rule, it returned validation error message: selected id is invalid.

I think system consider null as string 'null'.

So I tried like this.

$rule['id'] = 'required|exists:domains,id,website_id,' . null;

But same error.

Can anyone please help me?

Thanks!

Upvotes: 0

Views: 585

Answers (1)

lagbox
lagbox

Reputation: 50491

You can use 'NULL' as the value. It specifically looks for this value for when you want to do a WHERE NULL with the database related rules.

Upvotes: 1

Related Questions