I want to get user id in laravel 5.3 controller with Auth::user()->id but it creates error their

荒凉一梦 提交于 2019-12-02 07:50:54

Firstly lets hope you have a users table with the primary key id and a modal associated with it in your project. Try to use use Illuminate\Support\Facades\Auth; then

// This will check if user is logged in..
if (Auth::check()) {

       $user_id = Auth::user()->id;
       $points = Points::select(DB::raw("sum(p_add)-sum(p_less)  as Total"))->where('user_id', $user_id)->first();

       return view('mop.account-page', array('points'=>$points));
    } else {
        return redirect('somewhere'); // or return anything you want
    }
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!