在我今天得到的PHP Intelephense的最新更新之后,Intelephense一直显示我的路由(和其他类)的未定义符号的错误,以前没有这样的错误,它困扰着我。

以下是错误截图:

这是我的代码:

Route::group(['prefix' => 'user', 'namespace' => 'Membership', 'name' => 'user.'], function () {
    Route::get('profile', 'ProfileController@show')->name('profile.show');
    Route::patch('profile', 'ProfileController@update')->name('profile.update');
    Route::patch('change-password', 'ChangePasswordController@change')->name('change-password');
    Route::get('role', 'ProfileController@getRole')->name('profile.role');
    Route::get('summary', 'SummaryController@show')->name('summary');
    Route::get('reserved', 'AuctionController@reservedAuction')->name('reserved');
});

实际上,这段代码中没有错误,但intelephense一直显示错误,所以有办法解决这个问题吗?


当前回答

 use Illuminate\Support\Facades\Route;

添加上述命名空间

其他回答

use Illuminate\Support\Facades\Route;

警告导入相应的命名空间后消失。

版本的

幼虫 6+ VSCODE 版本 1.40.2 PHP Intelephense 1.3.1

我也有同样的问题,下面的内容似乎已经解决了这个问题。

a)更新至最新版本1.3.5,并重新启用所有诊断设置。

我还在接收信息

b)将带有依赖库的vendor文件夹添加到工作区

这似乎解决了问题。

下面是我解决的问题:

打开扩展设置:

然后搜索你想要更改的变量,然后取消选中它

你应该考虑的变量有:

intelephense.diagnostics.undefinedTypes 
intelephense.diagnostics.undefinedFunctions         
intelephense.diagnostics.undefinedConstants         
intelephense.diagnostics.undefinedClassConstants 
intelephense.diagnostics.undefinedMethods 
intelephense.diagnostics.undefinedProperties 
intelephense.diagnostics.undefinedVariables

在我的例子中,由于某种原因,供应商文件夹在VS Code设置中被禁用:

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

通过删除包含供应商文件夹的行,它可以在Intelephense 1.5.4版本上正常工作

我找到的唯一可行的解决方案是:

设置语言模式为Blade(使用扩展:Laravel Blade格式化器) 这将解决问题。否则,请按照此步骤操作。

这些类不存在于工作区中。Laravel在运行时创建它们。因此,它们被报告为未定义的。解决方案是提供存根定义

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

或关闭诊断(intelephense.diagnostics.undefinedTypes)。