【发布时间】:2015-12-17 20:19:26
【问题描述】:
我有这个表武器,其中包含武器 ID、武器名称、wStock、wDesc 列
在控制器内部的更新函数中,我有这组规则
public function c_updateSystemUser($id)
{
$rules = array(
'weaponName' => 'required|min:2|max:50|regex:/^[a-zA-Z0-9\-\s]+$/|unique:weaponTbl,weaponName,' . $id,
'wStock' => 'required|numeric',
'wDesc' => 'required|min:1|max:100|regex:/^[a-zA-Z0-9\-\s]+$/'
);
//other stuff
}
当我更新并只更改 wStock 时,它遇到了问题,因为它说武器名称已经存在。所以我使用了独特的规则
unique:weaponTbl,weaponName,' . $id,
因为我想排除我目前正在处理的记录,但是当我测试它时,我遇到了这些错误
Column not found: 1054 Unknown column 'id' in 'where clause'
(SQL: select count(*) as aggregate from `weaponTbl` where `weaponName` = unicorn and `id` <> 1)
为什么它只使用 id 而我的表中没有任何“id”而只有武器 ID?有没有办法解决这个问题?
【问题讨论】:
标签: php laravel laravel-4 laravel-validation