laravel同时更新2个表列

时间:2019-03-19 06:26:31

标签: laravel-5.4

我已经研究了一段时间了,这个问题是由Laravel 5.4的雄辩关系造成的,在这种情况下,我想做的是接受用户验证并更新其verif_level (来自用户的列名)到级别'2',现在,verify_accounts表的结构包括其ID和user_id,这是来自users表的外键。现在,一切正常,但是在users表上更新的verif_level的id与verification_accounts表的id相同,其user_id为9459,在users表上更新的数据也为9,具有相同的值Verification_accounts表上的值。应该是将9459的verif_level更新为2级,这是控制器的代码:

 public function updateVerification(Request $request) 
{
    $validator = \Validator::make($request->all(), [
        'admin_feedback' => 'required', 
    ]);
    $verification = VerificationAccount::find($request->id)->load('user');
    $user = User::find($request->id);
    if ($validator->passes())
        if($verification->verification_level == '1'){
            $verification->status = 1;
            $verification->proccessed_by = \Auth::user()->id;
            $verification->admin_feedback = $request->admin_feedback;
            $verification->save();
            $user->verif_level = '2';
            $user->save();
            return  response()->json(['success' => true,'message' => 'Verification successfully updated']);
        }
        else{
            return  response()->json(['success' => false,'message' => 'Verification already accepted']);
        }
    else{
        return ['error' => $validator->errors()];
    }
}

但是当我执行“ $ request-> user_id”时,它返回创建空对象数组的错误。并知道如何处理?

0 个答案:

没有答案