未定义的类路由(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
Undefined class Route (Laravel in PhpStorm)
提问by Maxim Vasiliev
回答by Bxx
Check the Laracasts walkthrough
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日):
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 .gitignore
file
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 .gitignore
and _ide_helper.php
files into PhpStorm
7) 将.gitignore
和_ide_helper.php
文件下载到 PhpStorm
This is what my PhpStorm project directory looks like afterwards:
这是我的 PhpStorm 项目目录之后的样子:
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 后,“未定义类”错误将消失,自动完成现在可以工作。可能需要重新启动它。
回答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.php
file (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 $foo
variable is type of Foo
class.
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.php
since 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 use
simply acts as a reference for PHP.
编辑:以上不会给 PHP 增加任何开销,因为它use
只是作为 PHP 的参考。