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


当前回答

在v1.7.1中也有同样的问题。它在内置函数上显示错误。但刚刚发现解决方案:去扩展设置@ext:bmewburn。vcode - Intelephense -client并逐个禁用Intelephense›Diagnostics:您将看到错误显示将停止。

其他回答

我最近解决了自己的问题。通过文件>首选项 我在寻找智慧 有文件的部分被排除了,我注意到供应商文件夹被添加了。 我把它删除了,现在我所有的laravel文件都有索引了

在你的web。php中

添加这行代码

use Illuminate\Support\Facades\Route;

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

use Illuminate\Support\Facades\Auth;

谢谢。

如果您知道您的问题仅限于Facades,并且您正在运行Laravel 5.5或更高版本,那么这个解决方案可能会对您有所帮助。

安装laravel-ide-helper

编译器需要——dev barryvdh/ laravell -ide-helper

在AppServiceProvider中添加这个条件语句来注册helper类。

public function register()
{
    if ($this->app->environment() !== 'production') {
        $this->app->register(\Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class);
    }
    // ...
}

然后运行php artisan IDE -helper:generate生成一个文件来帮助IDE理解Facades。您需要重新启动Visual Studio Code。

参考文献

https://laracasts.com/series/how-to-be-awesome-in-phpstorm/episodes/16

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

不,只有在自动更新Intelephense扩展后才会出现错误。

要解决这个问题,您可以通过单击Intelephense扩展中的“安装另一个版本”将其降级到以前的版本。版本1.2.3上没有错误。

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