Search code examples
laravellaravel-authentication

Laravel Auth::user()->id returns 0 on custom id


I am trying to make a User object with a String as ID. Everything went fine, even authenticating. But whenever I am trying to get the currently logged in user his ID by either:

Auth::user()->id

or

Auth::id();

Both are returning '0'. Whenever I dump the Auth::user object I can actually see the id attribute correctly. Have I done something wrong?


Solution

  • Laravel tries to cast it to integer, simply put the following property in your User class.

    class User {
        public $incrementing = false; 
    }