Laravel 5.2存在验证无法找到列

时间:2017-03-19 15:16:40

标签: laravel-5.2 laravel-validation

我在验证request中的controller时遇到了麻烦。我使用exists验证规则。用户应该提交integer。此整数应在id表的单行中以user_courses形式存在。此行还应使列user_id等于158 - docs

我的验证规则

'course_id' => 'integer|exists: user_courses, id, user_id, 158'

取而代之的是

  

Connection.php第333行中的PDOException:SQLSTATE [42S22]:列不是   发现:1054'where子句'中的未知列'id'

我的表

id, user_id, created_at, updated_at

1 个答案:

答案 0 :(得分:1)

问题在于空间:

'course_id' => 'integer|exists: user_courses, id, user_id, 158' // incorrect

'course_id' => 'integer|exists:user_courses,id,user_id,158' // correct

原始代码会混淆laravel来搜索这样的列名:

' user_courses'