Search code examples
laravelphpstorm

Property 'id' not found in Illuminate\Contracts\Auth\Authenticatable|null


How can I get around this warning in PhpStorm?

Property 'id' not found in Illuminate\Contracts\Auth\Authenticatable|null

for

auth()->user()->id

Note, that this question relates to PhpStorm not Laravel. The id exists and Laravel doesn't show the warning. The IDE does.


Solution

  • Phpstorm does not know about the object. You can add something like this to your user model:

    /**
     * @property int $id
     */
    
    class User ....