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

1

8

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)

Entoderm answered 26/2, 2021 at 4:55 Comment(3)
Do you have use Illuminate\Support\Facades\Route; at the top of your web.php?Chimpanzee
@Chimpanzee If that added in alias then no need to import in a particular file. That's the advantage of using an alias.Entoderm
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.Chimpanzee
C
9

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

Chimpanzee answered 26/2, 2021 at 5:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.