您好我正在Laravel中进行一些验证,我想确保字段uid对于project_id是唯一的。例如,我的数据库表如下:
id | project_id | uid |
1 | 3 | task_uid |
2 | 4 | task_uid2 |
3 | 4 | task_uid |
uid可以在project_id中存在两次,但如果project_id相同则不存在。
我尝试了以下内容;
public static $rules = array(
'UID' => 'required|unique:uid,project_id'
);
但是这没有用,并返回以下sql错误;
"SQLSTATE[42S02]: Base table or view not found: 1146 Table 'project.uid' doesn't exist (SQL: select count(*) as aggregate from `uid` where `project_id` = task_uid)"
我有什么想法可以检查任务表以确保project_id和uid是唯一值?
答案 0 :(得分:5)
**请注意:这是Laravel 4 **
独特的方式( laravel 4 ):
unique:{tableName},{columnName}
尝试
public static $rules = array(
'UID' => 'required|unique:{tableName},uid|unique:{tableName},project_id'
);
**请注意:这是Laravel 4 ****