Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undefined type 'DB'. Intelphense (1009) in Laravel 6 Controller #945

Closed
mofizul21 opened this issue Jan 9, 2020 · 10 comments
Closed

Undefined type 'DB'. Intelphense (1009) in Laravel 6 Controller #945

mofizul21 opened this issue Jan 9, 2020 · 10 comments

Comments

@mofizul21
Copy link

Describe the bug
It's an unexpected error notice when working with Laravel 6 that Undefined type 'DB'.

Expected behavior
It should not display the error notice.

Screenshots
You can see the error notice screenshot here

Platform and version
Windows 10, 64 bit. Intelphsense 1.3.7

@mstroink
Copy link

mstroink commented Jan 9, 2020

Same issue (or related?) after update to 1.3.7.

Schermafbeelding 2020-01-09 om 21 05 25

@bmewburn
Copy link
Owner

bmewburn commented Jan 9, 2020

@mofizul21 those laravel global namespaced facades like DB don't have a concrete definition in the workspace and cannot be indexed. To get around this you can use https://github.com/barryvdh/laravel-ide-helper or if you prefer set intelephense.diagnostics.undefinedTypes to false in settings.

@mstroink that's a strange one. It looks like it has found the definition to provide the hover. Can you share some code that reproduces the issue?

@bmewburn
Copy link
Owner

Closing as original issue has a solution. @mstroink if you are still experiencing this please open a new ticket with a code example.

@tsu1980
Copy link

tsu1980 commented Jun 1, 2020

Try use Illuminate\Support\Facades\DB; instead of use DB;

@moniruzzaman97m
Copy link

moniruzzaman97m commented Mar 13, 2021

Undefined type 'Database\Seeders\DB'
Try

use Illuminate\Support\Facades\DB;

@khanks
Copy link

khanks commented May 16, 2021

@mofizul21 those laravel global namespaced facades like DB don't have a concrete definition in the workspace and cannot be indexed. To get around this you can use https://github.com/barryvdh/laravel-ide-helper or if you prefer set intelephense.diagnostics.undefinedTypes to false in settings.

@mstroink that's a strange one. It looks like it has found the definition to provide the hover. Can you share some code that reproduces the issue?

If you installed the latest version of barryvdh/laravel-ide-helper and you're NOT on Laravel 8, you'll probably need to grab an older version of it. I already had it installed but I was still getting this error message (even tho the code actually works). So I browsed his github and found version 2.8.2 which still supported Laravel prior to version 8 (which is sensible cuz I hate "breaking changes" that cause me to change code). Here's the composer command: composer require --dev barryvdh/laravel-ide-helper:2.8.2 . THAT version made this error message go away. Hope this helps someone.

@davijb3
Copy link

davijb3 commented Feb 1, 2022

I was having the same problem. I managed to solve it by correctly adjusting the "namespace" of the class I was calling, as I noticed it wasn't right. I don't know if this is your case, but it doesn't hurt to check.

@AzPrime44
Copy link

Try use Illuminate\Support\Facades\DB; instead of use DB;

I worked !!! thanks bro

@YannickTamburrini
Copy link

For those who use VSCode with Intelephense, you can try composer require capsule/di -W. I did that and the error disappeared, so I could use Capsule having the types. Hope this helps some folks. In my case, I had no rights to change the composer.json file, but reverting the changes didn't make the squiggly lines appear again.

@CreateWithCoding
Copy link

like those ahead said and most simply is this with no complexities:

use Illuminate\Support\Facades\DB;
// use DB;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants