Problem with unique rule in validation on Update?


#1

Hello,

I have a validation rule in my validation like this

ean13: ‘unique:products,id,productId|required_if:active_bol_be|required_if:active_bol_nl|max:20’

Problem is that the rule still is checked on update products ?
productId is a known var with the id in it ?

What am i doing wrong ?

thanks


#2

You’re missing ‘fieldname’

Should be:
ean13: 'unique:products,ean13,id,productId|...'

In otherwords, ean13 must be unique within the products table, unless the id field = the provided value.

See: unique(tableName, [fieldName], [ignoreField], [ignoreValue])


#3

Still does not work !


#4

actually… sorry that should be:

ean13: `unique:products,ean13,id,${productId}|...`

productId’s value has to get populated into the rule.


#5

And… Still NOT work !


#6

And you’re certain that productId contains the value of the id field of the product being updated?

Something must not be right. need more info


#7

Looked agaib to it and… it works !

I forget the backticks !

Thanks a lot !