AndySong's avatar

auth()->user() does not have methods in User model(laravel-ide-helper)

Hi I have trouble with autocompleting methods in User model when I use auth()->user()

so I have a method foo in User model, and when I use auth()->user() to get the login user instance I do not have the foo method show up.

can some one tell me what congfig I need to do?

0 likes
7 replies
Snapey's avatar

I dont think you can do that because ypur IDE has no idea that auth()->user() helper relates to the User class

1 like
AndySong's avatar

@SNAPEY - I found a workaround, but it is still not ideal. but anyway at least it removes the error for phpStrom.

tykus's avatar

Assign a variable and add an annotation to give your IDE a typehint (within the scope that the variable will be used):

/** @var App\User $user */
$user = auth()->user();
AndySong's avatar

@TYKUS - yes, but I really do not like comment/Docs in my code. I try to keep those as less as possible. and it's not very fluent, Thank you for ur help.

click's avatar
click
Best Answer
Level 35

I like to create a helper method user(). This is short and you can set your own return statement.

Or you could use \Auth::user() this does have the following return statement: @return \App\User|null (with the help of the ide-helper library)

1 like

Please or to participate in this conversation.