Laravel Guard.php第453行中的ErrorException

Laravel Guard.php第453行中的ErrorException,laravel,Laravel,尝试登录时出错 $set_user = DB::table('v_user_branch') ->select('id', 'company_information_id') ->where('users_id','=',$user->id) ->where('default_branch','=',1); ->get()[0];

尝试登录时出错

    $set_user = DB::table('v_user_branch')
                ->select('id', 'company_information_id')
                ->where('users_id','=',$user->id)
                ->where('default_branch','=',1);
                ->get()[0];

    session()->put('company_information_id', $set_user->company_information_id);
    session()->put('branch_id',$set_user->id);

试试这个

$set_user = DB::table('v_user_branch')
                ->select('id', 'company_information_id')
                ->where('users_id','=',$user->id)
                ->where('default_branch','=',1);
                ->first();

函数的作用是:返回一个集合;不是数组。如果只需要第一个实例,请使用first()方法

Try first()replace get()很抱歉得到了结果,在我的视图表(v_user_分支)中没有可用的数据。正如您所提到的,它也在工作。多谢各位@纳比尔·法汉