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

后端 未结 18 1776
小鲜肉
小鲜肉 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:41

    Now with laravel 4.2 it is easy to get user's id:

    $userId = Auth::id();
    

    that is all.

    But to retrieve user's data other than id, you use:

    $email = Auth::user()->email;
    

    For more details, check security part of the documentation

提交回复
热议问题