I am resolving a class in Laravel 10 like the following:
$myService = resolve(MyService::class);
$myService->methodOnMyServiceClass();
However, in PhpStorm, I cannot click through to the method, and it says:
"Cannot find declaration to go to"
Is this something to do with the Laravel resolve()
method that my IDE is not recognising? It's frustrating because the function name is now greyed out like it's not being used.
I'm having to use resolve()
because I was previously writing $myService = new MyService()
, but my dependency injection was not working without me resolving the class.
Any ideas please? Thanks.
You can give a doc line by specifying the type of a variable. This will help the IDE understand it's class
/** @var MyService $myService */
$myService = resolve(MyService::class);
$myService->methodOnMyServiceClass();