为什么提示 avatar_image_id 不存在呢?

 "message": "The given data was invalid.",

"errors": {

"avatar_image_id": [

"avatar image id 不存在。"

]

},
'avatar_image_id'=>'exists:images,id,type,avatar,user_id,'.$userId
《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
《G01 Go 实战入门》
从零开始带你一步步开发一个 Go 博客项目,让你在最短的时间内学会使用 Go 进行编码。项目结构很大程度上参考了 Laravel。
讨论数量: 2

exists:table,column

'avatar_image_id' => 'exists:images,id,

如果你想要验证在images表下user_id等于$userId时,avatar_image_id是否存在的话,你可以这样

 'avatar_image_id' => [
        Rule::exists('images')->where(function ($query) {
            $query->where('user_id', $userId);
        }),
    ],
4年前 评论
jackzheng9969 (楼主) 4年前
message": "Method Illuminate\\Validation\\Rules\\Exists::__toString() must not throw an exception, caught ErrorException: Object of class Closure could not be converted to string",
    "code": 1,
    "status_code": 500,
    "debug": {
        "line": 0,
        "file": "/home/vagrant/code/larabbs/vendor/laravel/framework/src/Illuminate/Validation/ValidationRuleParser.php",
        "class": "Symfony\\Component\\Debug\\Exception\\FatalErrorException",
                'avatar_image_id'=>[
                        Rule::exists('images',function ($query){
                            $query->where('user_id',(int)$userId);
                        })
                    ]
4年前 评论
CasperNan 4年前

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!