Undefined class Route (Laravel in PhpStorm)
LaravelAutocompletePhpstormLaravel FacadeLaravel Problem Overview
Laravel Solutions
Solution 1 - Laravel
Check the Laracasts walkthrough
-
Click on the gist
Generated version for L5: https://gist.github.com/barryvdh/5227822
- Click on "Raw" to get the current version (as of June 22, 2016 it is):
-
Make sure you're in your root directory (this is mine)
cd /var/www/html/project
-
Download the gist:
-
Add "_ide_helper.php" to the
.gitignore
filesudo nano .gitignore
Add "_ide_helper.php" on a new line at the bottom
- Download the
.gitignore
and_ide_helper.php
files into PhpStorm
This is what my PhpStorm project directory looks like afterwards:
- After the files are downloaded into PhpStorm, the "Undefined class" error will disappear and autocompletion will now work. Might need to restart it.
Solution 2 - Laravel
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.
Solution 3 - Laravel
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.