Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Laravel 6.6 - Unidentified symbol 'Route' in routes/web.php #780

Closed
dissolvdgrl opened this issue Dec 3, 2019 · 17 comments
Closed

Laravel 6.6 - Unidentified symbol 'Route' in routes/web.php #780

dissolvdgrl opened this issue Dec 3, 2019 · 17 comments

Comments

@dissolvdgrl
Copy link

dissolvdgrl commented Dec 3, 2019

Today I opened VS Code to start working on my Laravel 6 project and suddenly I get an error in my routes/web.php file saying: "Undefined symbol 'Route'.

Also getting the following error in my FormsController.php (fresh controller, no error using Intelephense 1.2.3):

Expected type 'Illuminate\Http\Request'. Found 'Illuminate\Http\Request|string|array'.

I googled around and found this Stackoverflow post describing the problem and a fix.

FIX: downgrade to 1.2.3

It seems that Intelephense 1.3.0 introduced this problem. The error is quite annoying.

I am on Windows 10 using Intelephense 1.3.0

@bmewburn
Copy link
Owner

bmewburn commented Dec 3, 2019

You don't need to downgrade you can:

Either disable undefined symbol diagnostics in the settings -- "intelephense.diagnostics.undefinedSymbols": false .

Or use an ide helper that adds stubs for laravel facades. See https://github.com/barryvdh/laravel-ide-helper . Also see https://laracasts.com/series/how-to-be-awesome-in-phpstorm/episodes/15 , it discusses phpstorm but is somewhat applicable.

Please open a separate issue for the type error with some example code.

@johanvanhelden
Copy link

johanvanhelden commented Dec 3, 2019

@bmewburn Generating the _ide_helper.php file (using ./artisan ide-helper:generate) seemed to have fixed the issue. Before, only the .phpstorm.meta.php was enough and generating the _ide_helpers.php file even caused auto-completion issues, results were shown twice.

Now, due to generating the _ide_helpers.php file, the auto-completion issues are back again. Results are now shown 2 times, for example the Session and Storage facades:

Screenshot from 2019-12-03 13-21-34

Screenshot from 2019-12-03 13-24-58

Because those classes are also in the _ide_helper.php file.

So I think duplicate entries need to be filtered out by the extension, or the extension should work, like before, with only the php storm meta file.

@bmewburn
Copy link
Owner

bmewburn commented Dec 3, 2019

@johanvanhelden I didnt think the laravel-ide-helper .phpstorm.meta.php had definitions. Are you sure there is not a second _ide_helper.php in the project? Also see if reindexing helps ctrl + shift + p -> Index workspace

@andersespedalen
Copy link

@bmewburn Disabling undefined symbol diagnostics doesn't solve the issue. My goal is not to hide the red squiggly lines, but to have class/function/attribute doc-lookup and click-navigation.

I'd rather roll back to a previous version of intelephense where this worked.

@johanvanhelden
Copy link

johanvanhelden commented Dec 3, 2019

@bmewburn Yes, there is only 1 ide_helper file in the project ,and I also tried re-indexing the project.

If I remove the _ide_helper file, re-index the project the duplicate entries are gone, but the Route file is broken since it can not resolve the global facade's.

If I re-generate the helper file and re-index the project the route file is fixed, but there are duplicate auto-complete entries.

@johanvanhelden
Copy link

johanvanhelden commented Dec 3, 2019

@bmewburn I really think it's something to do with the internals of the extension. Since if I alt-click the class, it does show the original definition (the one in /laravel/framework/src/Illuminate/Support/Facades/Route.php) and the ide_helper definition.

The ide_helper does not help to point to /laravel/framework/src/Illuminate/Support/Facades/Route.php, so it was able to figure that out by itself. Without the help of the ide_helper file.

So why, if I remove the ide_helper file, does it all of a sudden not know it should resolve to /laravel/framework/src/Illuminate/Support/Facades/Route.php?

Screenshot from 2019-12-03 14-35-27

@thinkstudeo
Copy link

thinkstudeo commented Dec 4, 2019

I have similar problems after the update and agree with @johanvanhelden - ide_helper.php does show duplicate entries.

Another problem I am encountering is that when I use Illuminate\Database\Eloquent\Relations methods like hasMany or belongsTo any relationship method for that matter in a Trait which is used by Eloquent Model class it shows undefined symbol for hasMany or belongsTo.

So any method which is not declared within the file is giving undefined symbol warning/error. This wasn't the case till the latest update.

So am thinking to revert back to the previous release till this gets sorted out.

Either disable undefined symbol diagnostics in the settings -- "intelephense.diagnostics.undefinedSymbols": false .

If I disable the undefinedSymbols - will I not miss out the actual warnings/errors also?

@blagi
Copy link

blagi commented Dec 4, 2019

I have a similar problem but with complex Symfony application and some USE statements. 1.3.1 didn't solved a problem.
And yes I'd like to know what is undefined.

@bmewburn
Copy link
Owner

bmewburn commented Dec 4, 2019

@johanvanhelden I think you are getting multiple go to definitions there because you have

use Illuminate\Support\Facades\Route;

And _ide_helper.php seems to define Illuminate\Support\Facades\Route as does vendor/laravel/framework/src/Illuminate/Support/Facades/Route.php. I'm unsure why the ide helper creates a stub for this when it can be discovered in the laravel source.

This does not explain why the duplicate globally namespaced facades are shown twice though. There must be another file where they are being defined. Are you able to do a text search for class Route and list the paths to globally namespaced definitions? I'm unable to reproduce this on a fresh laravel install.

@johanvanhelden
Copy link

johanvanhelden commented Dec 5, 2019

@bmewburn is this helpful?

./_ide_helper.php:10925:    class Route {
./_ide_helper.php:21349:    class Route extends \Illuminate\Support\Facades\Route {}
./vendor/symfony/routing/Annotation/Route.php:22:class Route
./vendor/symfony/routing/Route.php:20:class Route implements \Serializable
./vendor/laravel/framework/src/Illuminate/Routing/Route.php:20:class Route
./vendor/laravel/framework/src/Illuminate/Support/Facades/Route.php:38:class Route extends Facade

Btw, both the global facades are duplicated, but also the non-global ones like Illuminate\Support\Facades\Route and Illuminate\Support\Facades\Session.

Can this behavior not be rolled back to the 1.2 way? Since 1.2 was able to detect the Route facade just fine without the ide_helper file. I still don't fully understand why or how this changed. Could you explain that a bit more to help me understand?

@Zolak94
Copy link

Zolak94 commented Dec 6, 2019

I have 1.3.1 version and I still have this problem.

@johanvanhelden
Copy link

Yes, the problem persists in 1.3.1 - either with duplicate auto-completion entries with the ide-helpers file, or the unidentified symbol without it.

@thinkstudeo
Copy link

I don't think that ide-helpers file is required. For me it works without the ide-helpers file except for:

  • Methods which are pulled in from other packages and referenced via a variable instead of class.
  • Laravel eloquent relation methods like hasMany belongsTo etc when they are defined in a trait and not on model class.

The above two cases gives me Undefined symbol error - I have provided example file in #829

@bmewburn
Copy link
Owner

bmewburn commented Dec 7, 2019

@johanvanhelden I managed to repro your issue with the following and with _ide_helper

<?php
use Illuminate\Support\Facades\Route;
Rout|

The duplicate Route suggestions are actually separate items. One for the import and one for the global Route facade defined in _ide_helper. So this is correct but it could be improved to display this better. There are duplicates that display as Route [Illuminate\Support\Facades] because _ide_helper and laravel core both define this. I have opened #843 to track this.

@thinkstudeo I'll look into your issue in the other ticket.

I'd recommend that anyone else seeing undefined laravel types to use https://github.com/barryvdh/laravel-ide-helper . The diagnostic will no longer appear and you will get completion suggestion too. If for some reason you don't want to or cant then there is #824 to disable undefined diagnostics for specific symbol kinds.

I'm closing this one given that the OP is no longer experiencing an issue.

@bmewburn bmewburn closed this as completed Dec 7, 2019
@mahmudulhsn
Copy link

mahmudulhsn commented Jan 23, 2020

use Illuminate\Support\Facades\Route; in web.php. It works for me.

Screenshot from 2020-01-23 18-47-57

@Danger-Mkh
Copy link

just need to change "intelephense.diagnostics.undefinedTypes": false
no matter what version you have

@adrian-zawada
Copy link

In my case, for some reason, vendor folder was disabled on VS Code settings:

    "intelephense.files.exclude": [
        "**/.git/**",
        "**/.svn/**",
        "**/.hg/**",
        "**/CVS/**",
        "**/.DS_Store/**",
        "**/node_modules/**",
        "**/bower_components/**",
        "**/vendor/**", <-- remove this line!
        "**/resources/views/**"
    ],

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants