Php 用于使用主键和外键检查唯一性的Laravel表单验证规则
我知道如何使用以下单个id检查唯一性Php 用于使用主键和外键检查唯一性的Laravel表单验证规则,php,laravel,laravel-4,eloquent,laravel-validation,Php,Laravel,Laravel 4,Eloquent,Laravel Validation,我知道如何使用以下单个id检查唯一性 $addrules = array( 'GradeName' => array('required','regex:/^./','unique:class,GradeName,'.$id.',AutoID'), ); 然后我想使用检查唯一的两个id(主键和外键) 这是我的代码: $update = array( 'GradeName' => ar
$addrules = array(
'GradeName' => array('required','regex:/^./','unique:class,GradeName,'.$id.',AutoID'),
);
然后我想使用检查唯一的两个id(主键和外键)
这是我的代码:
$update = array(
'GradeName' => array('required','regex:/^./','unique:class,GradeName,'.$schoolid.',schoolid,'.$data.',AutoID'),
);
但我有以下错误:
SQLSTATE[42S22]: Column not found: 1054 Unknown column '20' in 'where clause' (SQL: select count(*) as aggregate from `class` where `GradeName` = g1 and `schoolid` <> 3 and `20` = AutoID)
SQLSTATE[42S22]:未找到列:在“where子句”中找到1054个未知列“20”。(SQL:选择count(*)作为“class”的聚合,其中“GradeName”=g1和“schoolid”3和“20”=AutoID)
如何解决这个问题?您传递了错误的参数,后面是doc
unique:table,column,except,idColumn
You may also specify more conditions that will be added as "where" clauses to the query:
'email' => 'unique:users,email_address,NULL,id,account_id,1'
In the rule above, only rows with an account_id of 1 would be included in the unique check.
所以,您可以按自己的方式传递foregein密钥 我已使用以下代码修复了此错误
$update = array(
'GradeName' => array('required','regex:/^./','unique:class,GradeName,'.$data.',AutoID,schoolid,'.$schoolid),
);
上面和下面的数组元素数不匹配???@nbin我无法理解??我有以下错误“SQLSTATE[42S22]:未找到列:1054 where子句中的未知列“3”(SQL:选择count(*)作为从
class
中的聚合,其中GradeName
=g1和3
schoolid和20
=AutoID)”抱歉,还应使用第二个参数更改顺序。更改$data和AutoID。我编辑的帖子有以下错误“SQLSTATE[42S22]:未找到列:在where子句中1054未知列“3”(SQL:选择count(*)作为从class
whereGradeName
=g1和3
schoolid和AutoID
=20)的聚合)