Reputation: 166
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
wherebarcode
= 5391510260790 andid
<> 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?
Upvotes: 2
Views: 2163
Reputation: 968
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',
Upvotes: 0
Reputation: 62228
You can specify the column to check using the fourth parameter to the rule:
'barcode' => 'required|unique:item,barcode,'.$this->get('itemId').',itemId',
Upvotes: 3