Search code examples
phplaravelvisual-studio-codealiasintelephense

Why showing error undefined when using alias defined values in laravel application through VS code php intelephense extension?


In config/app.php

'aliases' => [
    'Route' => Illuminate\Support\Facades\Route::class,
],

when I am using Route in routes/web.php like

Route::get('/', 'UserController@home');

I installed php intelephense extension in my vs code. So that it is showing error like

enter image description here

Does anyone have any idea how to fix this issue? (Functionality is working fine but it is showing like the error is the problem)


Solution

  • Aliases are registered at runtime so they are not in the namespace and Intelephense cannot pick them up.

    See the question asked on the Intelephense project in Github https://github.com/bmewburn/vscode-intelephense/issues/1116

    "These classes don't exist in the workspace. Laravel creates them at runtime. As such they are reported as undefined. The solution is to either provide stub definitions https://github.com/barryvdh/laravel-ide-helper or turn off the diagnostics (intelephense.diagnostics.undefinedTypes)."