phpstorm autocomplete customModelMethod() in controller class

Published 2 years ago by t0ne

i've got autocomplete running barry ide helper etc. but there's one thing i can't figure:

//inside a controller method
$user = User::findOrFail(1);
 $test = $user->getMethodMadeByMeInTheUserClass();
//phpstorm: method 'getMethodMadeByMeInTheUserClass' not found in ......Eloquent/Collection\.....Eloquent/Model

findOrFail returns a Eloquent Model, but i want to get autocomplete on the User model also (which contains 'getMethodMadeByMeInTheUserClass' method)

I to fix this is phpstorm? thanks in advance!

Francismori7
/** @var App\User $user */
$user = User::findOrFail(1);
t0ne
t0ne
2 years ago (10,335 XP)

thanks!

and this will work, strange.. User::findOrFail(1)->getMethodMadeByMeInTheUserClass();

Francismori7

findOrFail has a @return docblock that specifies it returns a new instance of static (meaning itself)

Please sign in or create an account to participate in this conversation.