英文:
Resolving classes in Laravel leads to PhpStorm "Cannot find declaration to go to"
问题
我正在解决一个类似以下方式的Laravel 10中的类:
$myService = resolve(MyService::class);
$myService->methodOnMyServiceClass();
然而,在PhpStorm中,我不能点击到这个方法,并且它显示:
"无法找到要跳转的声明"
这与Laravel的resolve()
方法有关,我的IDE没有识别到吗?这令人沮丧,因为函数名现在变成灰色,好像它没有被使用。
我不得不使用resolve()
,因为之前我写了$myService = new MyService()
,但是我的依赖注入没有工作,除非我解决这个类。
请问有什么建议吗?谢谢。
英文:
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.
答案1
得分: 0
/** @var MyService $myService */
$myService = resolve(MyService::class);
$myService->methodOnMyServiceClass();
英文:
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();
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论