未定义的类路由(PhpStorm 中的 Laravel)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/37419143/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 17:22:09  来源:igfitidea点击:

Undefined class Route (Laravel in PhpStorm)

laravelautocompletephpstormlaravel-facade

提问by Maxim Vasiliev

How can I fix this alert in PhpStorm?

如何在 PhpStorm 中修复此警​​报?

enter image description here

在此处输入图片说明

And also how to get autocompletion for Route and other Facades?

以及如何获得 Route 和其他 Facades 的自动完成功能?

回答by Bxx

Check the Laracasts walkthrough

检查Laracasts 演练

1) Go to: https://github.com/barryvdh/laravel-ide-helper

1)前往:https: //github.com/barryvdh/laravel-ide-helper

2) Click on the gist

2)点击要点

Generated version for L5: https://gist.github.com/barryvdh/5227822

L5 生成版本:https: //gist.github.com/barryvdh/5227822

3) Click on "Raw" to get the current version (as of June 22, 2016 it is):

3)点击“Raw”获取当前版本(截至2016年6月22日):

https://gist.githubusercontent.com/barryvdh/5227822/raw/4d4b0ca26055fa4753b38edeb94fad2396c497c0/_ide_helper.php

https://gist.githubusercontent.com/barryvdh/5227822/raw/4d4b0ca26055fa4753b38edeb94fad2396c497c0/_ide_helper.php

4) Make sure you're in your root directory (this is mine)

4)确保你在你的根目录中(这是我的)

cd /var/www/html/project

5) Download the gist:

5)下载要点:

wget https://gist.githubusercontent.com/barryvdh/5227822/raw/4d4b0ca26055fa4753b38edeb94fad2396c497c0/_ide_helper.php

6) Add "_ide_helper.php" to the .gitignorefile

6)在.gitignore文件中添加“_ide_helper.php”

sudo nano .gitignore

Add "_ide_helper.php" on a new line at the bottom

在底部的新行上添加“_ide_helper.php”

7) Download the .gitignoreand _ide_helper.phpfiles into PhpStorm

7) 将.gitignore_ide_helper.php文件下载到 PhpStorm

This is what my PhpStorm project directory looks like afterwards:

这是我的 PhpStorm 项目目录之后的样子:

enter image description here

在此处输入图片说明

8) After the files are downloaded into PhpStorm, the "Undefined class" error will disappear and autocompletion will now work. Might need to restart it.

8) 文件下载到 PhpStorm 后,“未定义类”错误将消失,自动完成现在可以工作。可能需要重新启动它。

enter image description here

在此处输入图片说明

回答by Filip Koblański

There is greate IDE support for Laravel shipped from Baryvdh:

Baryvdh 提供了对 Laravel 的强大 IDE 支持:

https://github.com/barryvdh/laravel-ide-helper

https://github.com/barryvdh/laravel-ide-helper

after you install it you just call in the console:

安装后,您只需在控制台中调用:

php artisan ide-helper:generate

which generate alll facede shortcuts in _ide_helper.phpfile (which you have to exclude from git)

_ide_helper.php文件中生成所有 facede 快捷方式(您必须从 git 中排除)

There is also something special for PhpStorm:

PhpStorm 还有一些特别之处:

php artisan ide-helper:meta

which will give Laravel container context for example:

这将给出 Laravel 容器上下文,例如:

$foo = app(Foo::class);

PhpStorm will know that the $foovariable is type of Fooclass.

PhpStorm 会知道该$foo变量是类的Foo类型。

回答by TylersSN

I know this is an old thread, but it is still relevant. For me, I decided to add the following to my routes/web.phpsince I don't want to have to worry about regenerating meta data for the app.

我知道这是一个旧线程,但它仍然相关。对我来说,我决定将以下内容添加到我的,routes/web.php因为我不想担心重新生成应用程序的元数据。

use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\Auth;

Edit:The above does not add any overhead to PHP as the usesimply acts as a reference for PHP.

编辑:以上不会给 PHP 增加任何开销,因为它use只是作为 PHP 的参考。