7

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)

Senthurkumaran
  • 1,738
  • 2
  • 19
  • 29
  • Do you have ```use Illuminate\Support\Facades\Route;``` at the top of your ```web.php```? – Andrew Feb 26 '21 at 05:02
  • @Andrew If that added in alias then no need to import in a particular file. That's the advantage of using an alias. – Senthurkumaran Feb 26 '21 at 05:15
  • 1
    I understand how they work and I am not suggesting that you should have that line included. Whether or not you have it included helps me understand the source of the issue. – Andrew Feb 26 '21 at 05:54

1 Answers1

7

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)."

Andrew
  • 1,745
  • 1
  • 21
  • 29