为什么提示 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
《L05 电商实战》
从零开发一个电商项目,功能包括电商后台、商品 & SKU 管理、购物车、订单管理、支付宝支付、微信支付、订单退款流程、优惠券等
《L04 微信小程序从零到发布》
从小程序个人账户申请开始,带你一步步进行开发一个微信小程序,直到提交微信控制台上线发布。
讨论数量: 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年前

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