为什么提示 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
《L04 微信小程序从零到发布》
从小程序个人账户申请开始,带你一步步进行开发一个微信小程序,直到提交微信控制台上线发布。
《L03 构架 API 服务器》
你将学到如 RESTFul 设计风格、PostMan 的使用、OAuth 流程,JWT 概念及使用 和 API 开发相关的进阶知识。
讨论数量: 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年前

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