Undefined class Route (Laravel in PhpStorm)
Asked Answered
S

4

53

How can I fix this alert in PhpStorm?

enter image description here

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

Shadoof answered 24/5, 2016 at 16:29 Comment(2)
1) blog.jetbrains.com/phpstorm/2015/01/… 2) confluence.jetbrains.com/display/PhpStorm/…Nucleotide
Thank you. That is what I need.Shadoof
B
74

Check the Laracasts walkthrough

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

2) Click on the gist

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

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

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

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

cd /var/www/html/project

5) Download the gist:

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

6) Add "_ide_helper.php" to the .gitignore file

sudo nano .gitignore

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

7) Download the .gitignore and _ide_helper.php files into PhpStorm

This is what my PhpStorm project directory looks like afterwards:

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.

enter image description here

Bandur answered 22/6, 2016 at 19:8 Comment(3)
Works like a charm, just as @Bandur explains.Bibi
To make this answer a bit more concise: Download the _ide_helper.php for your version of laravel from github.com/barryvdh/laravel-ide-helper and save the file in the project folder of your PHPStorm/IntelliJ project.Samathasamau
Or you could simply, you know, follow instructions there and it's even simpler! composer require --dev barryvdh/laravel-ide-helper and then php artisan ide-helper:generate - donePainless
G
31

There is greate IDE support for Laravel shipped from Baryvdh:

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)

There is also something special for PhpStorm:

php artisan ide-helper:meta

which will give Laravel container context for example:

$foo = app(Foo::class);

PhpStorm will know that the $foo variable is type of Foo class.

Glimmering answered 24/5, 2016 at 19:41 Comment(0)
E
25

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.

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.

Either answered 15/12, 2018 at 14:29 Comment(1)
Easy and effective solution that does not require installing extra modules.Anthropologist
R
0

I solved this problem simply by installing the Laravel idea plugin. Use the following link: https://laravel-idea.com/ You can install it on your phpstorm. Its good feature is that you can use it for 30 days for free and pay the amount after satisfaction.

Revive answered 19/1, 2023 at 13:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.