【问题标题】:Laravel 5.2 exists validation cannot find columnLaravel 5.2 存在验证找不到列
【发布时间】:2017-03-19 23:26:08
【问题描述】:

controller 中验证request 时遇到了奇怪的问题。我使用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

【问题讨论】:

    标签: laravel-5.2 laravel-validation


    【解决方案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'
    

    【讨论】:

    • 谢谢,我正在寻找与unique相同的东西,它是那里的水坝空间
    猜你喜欢
    • 2018-10-12
    • 2013-12-01
    • 1970-01-01
    • 2016-06-26
    • 2016-07-16
    • 1970-01-01
    • 2016-03-28
    • 2016-12-27
    • 1970-01-01
    相关资源
    最近更新 更多