PeteBatin's avatar

VS Code, Laravel and increased errors/warnings from Intelephense

Has anyone else noticed a sudden increase in warnings in the Problems tab of VS Code from the Intelephense Extension? Does anyone know if they've reduced the feature set for the freemium version and maybe that's why it's doing it?

It happened around last Thursday (12th Feb) where the most basic things are being falsely flagged up.

I also noticed that PHP Namespace Resolver had some updates recently which coincidently had an update on the 12th (first time in 3 years) but as a test I downgraded back to the the version from 3 years ago and the warnings below still appear.

Example: Working on a migration file I get the following errors

Undefined type 'Illuminate\Database\Migrations\Migration'. Undefined type 'Illuminate\Support\Facades\Schema'. Undefined type 'Illuminate\Database\Schema\Blueprint'. Undefined type 'Illuminate\Support\Facades\Schema'.

Or for a Model: Undefined type 'Illuminate\Database\Eloquent\Model'. Undefined type 'Illuminate\Database\Eloquent\Factories\HasFactory'.

0 likes
1 reply
LaryAI's avatar
LaryAI
AI
Best Answer
Level 58

Certainly! This is a recent and common issue affecting many Laravel developers using VS Code with the Intelephense PHP extension.

What's Going On?

Intelephense relies on symbol indexing: it reads all PHP files and builds an "index" of classes, functions, etc. If it can't find files for Laravel (usually in vendor/), it assumes they don't exist and flags them as undefined.

Root Causes and Solutions:


1. The Vendor Folder Is Excluded From Indexing

Recent updates to Intelephense, VS Code, or your workspace settings may have changed the exclude/include patterns. If vendor/ is excluded, Intelephense can't see Laravel's framework classes.

Check Your VS Code Settings:

  • Go to settings.json (User or Workspace).
  • Look for files.exclude, search.exclude, or intelephense.files.exclude.

Make sure vendor/ is NOT being excluded.
Example of a potential problem:

"files.exclude": {
    "**/vendor": true, // <-- should be false or absent
}

How to fix:

// Remove or set to false:
"files.exclude": {
    "**/vendor": false
},
"search.exclude": {
    "**/vendor": false
},
"intelephense.files.exclude": [
    "**/.git/**",
    "**/node_modules/**",
    // "**/vendor/**",   // <-- REMOVE THIS
]

2. You Recently Ran composer install with --no-dev or the Vendor Folder Is Missing

Make sure you've run a normal composer install, and that vendor/autoload.php and your Laravel dependencies exist.


3. Force Intelephense to Reindex

Sometimes the symbol index gets corrupted. You can manually trigger a reindex:

  • Open the Command Palette (Ctrl+Shift+P)
  • Type "Intelephense: Index workspace" and run it

4. Composer autoload Issues

Make sure you have a correct composer.json and up-to-date autoload:

composer dump-autoload

5. Try Clearing Intelephense Cache

  • Close VS Code
  • Delete the cache directory:
    • macOS/Linux: ~/.config/Code/User/workspaceStorage/
    • Windows: %APPDATA%\Code\User\workspaceStorage\
  • Reopen VS Code

Or through Command Palette:

  • Run "Intelephense: Clear Cache"

6. Still Not Working? Try Disabling Other Conflicting Extensions

Sometimes PHP Namespace Resolver or other PHP extensions interfere with Intelephense.
Try disabling all PHP-related extensions except Intelephense, reload, see if it resolves.


TL;DR Step-by-step:

  1. Ensure vendor/ is not excluded from Intelephense or VS Code settings.
  2. Run composer install and composer dump-autoload
  3. Use "Intelephense: Index workspace" from the command palette.
  4. If still broken, clear the Intelephense cache.
  5. Disable other extensions if necessary.
  6. Restart VS Code.

Common settings snippet to add to your settings.json:

{
  "intelephense.files.exclude": [
    "**/.git/**",
    "**/node_modules/**"
    // Do NOT include vendor here!
  ],
  "files.exclude": {
    "**/node_modules": true,
    "**/.git": true
    // Do NOT exclude vendor!
  }
}

References

If these solutions don't work, try uninstalling/reinstalling Intelephense or testing in a new workspace to isolate issues.

Let me know if you need further help!

Please or to participate in this conversation.