2
votes

I'm using itemId instead of id and when I validate as

'barcode'        => 'required|unique:item,barcode,' .$this->get('itemId'),

I get

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'id' in 'where clause' (SQL: select count(*) as aggregate from item where barcode = 5391510260790 and id <> 10)

How do I tell Laravel to use the itemId instead of id in the unique validation in the request class at the authorize() function?

2

2 Answers

3
votes

You can specify the column to check using the fourth parameter to the rule:

'barcode' => 'required|unique:item,barcode,'.$this->get('itemId').',itemId',
0
votes

If you see the documentation it said, you must follow the following structure to tell which one is the id column.

unique:table,column,except,idColumn

You have to replace the idColumn with the name of the id column of yours. So the final code will be like this:

'barcode' => 'required|unique:item,barcode,' .$this->get('itemId').',itemId',