在我今天得到的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一直显示错误,所以有办法解决这个问题吗?


当前回答

下面是我解决的问题:

打开扩展设置:

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

你应该考虑的变量有:

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版本上正常工作

 use Illuminate\Support\Facades\Route;

添加上述命名空间

如果您在添加一个新的Vendor类后立即看到这种情况,请务必运行VScode命令(control-shift-P)索引工作区

use Illuminate\Support\Facades\Route;

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

版本的

幼虫 6+ VSCODE 版本 1.40.2 PHP Intelephense 1.3.1

在你的web。php中

添加这行代码

use Illuminate\Support\Facades\Route;

然后你就完成了,如果你得到了认证错误,然后添加这行代码

use Illuminate\Support\Facades\Auth;

谢谢。