我使用 itemId
而不是 id
并且当我验证时
'barcode' => 'required|unique:item,barcode,' .$this->get('itemId'),
我明白了
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'id' in 'where clause' (SQL: select count(*) as aggregate from
item
wherebarcode
= 5391510260790 andid
<> 10)
如何告诉 Laravel 在 authorize()
函数的请求类中的唯一验证中使用 itemId
而不是 id
?
最佳答案
您可以使用规则的第四个参数指定要检查的列:
'barcode' => 'required|unique:item,barcode,'.$this->get('itemId').',itemId',
关于php - Laravel - 使用不同的 id 进行唯一验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34710476/