Laravel: Auth::user()->id trying to get a property of a non-object

后端 未结 18 1687
小鲜肉
小鲜肉 2020-12-04 11:42

I\'m getting the following error \"trying to get a property of a non-object\" when I submit a form to add a user, the error is apparently on the first line: Auth::user()->id

18条回答
  •  自闭症患者
    2020-12-04 12:28

    For Laravel 6.X you can do the following:

    $user = Auth::guard()->user();
    $user_id = $user->id;
    $full_name = $user->full_name;
    

提交回复
热议问题