Laravel 5.2存在验证找不到列
Laravel 5.2 exists validation cannot find column
我在 controller
中验证 request
时遇到了奇怪的问题。我使用 exists
验证规则。用户应该提交 integer
。此整数应作为 id
存在于 user_courses
table 的单行中。此行的列 user_id
也应等于 158
- docs。
我的验证规则:
'course_id' => 'integer|exists: user_courses, id, user_id, 158'
我得到了什么:
PDOException in Connection.php line 333: SQLSTATE[42S22]: Column not
found: 1054 Unknown column ' id' in 'where clause'
我的Table:
id, user_id, created_at, updated_at
问题出在空格中:
'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'
我在 controller
中验证 request
时遇到了奇怪的问题。我使用 exists
验证规则。用户应该提交 integer
。此整数应作为 id
存在于 user_courses
table 的单行中。此行的列 user_id
也应等于 158
- docs。
我的验证规则:
'course_id' => 'integer|exists: user_courses, id, user_id, 158'
我得到了什么:
PDOException in Connection.php line 333: SQLSTATE[42S22]: Column not found: 1054 Unknown column ' id' in 'where clause'
我的Table:
id, user_id, created_at, updated_at
问题出在空格中:
'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'