Certainly! This is a common issue in VS Code, especially with PHP projects that have deep inheritance chains (like Laravel's FormRequest → Request). VS Code itself doesn't provide deep PHP analysis out of the box, but you can fix this with the right extensions and some configuration.
Recommended Solution:
-
Install PHP Intelephense
This is the most popular and powerful PHP language server for VS Code. It provides advanced autocompletion, type inference, and deep inheritance recognition.
- Go to Extensions (
Ctrl+Shift+X) - Search for Intelephense and install it.
- Go to Extensions (
-
(Optional) Install Laravel Extra Intellisense
If you’re working with Laravel, this extension adds even more context and autocompletion for Laravel-specific features.
- Search for Laravel Extra Intellisense and install it.
-
Check Your Workspace Settings
Make sure your workspace is using the correct PHP version and that your
vendorfolder is not excluded from indexing. In your.vscode/settings.json:{ "intelephense.environment.phpVersion": "8.1", // or your PHP version "intelephense.files.exclude": [ "**/.git/**", "**/node_modules/**", "**/bower_components/**" ] } -
Regenerate Intelephense Index
Sometimes, Intelephense needs to re-index your project. Open the command palette (
Ctrl+Shift+P) and run:Intelephense: Index workspace -
Add PHPDoc Annotations (if needed)
If you have custom methods or properties injected by Laravel (like
$this->user()in requests), you can help Intelephense by adding PHPDoc annotations:/** * @method \App\Models\User|null user() */ class MyFormRequest extends FormRequest { // ... }
Summary
- Install Intelephense (and optionally Laravel Extra Intellisense)
- Ensure your workspace is configured correctly
- Re-index if needed
- Use PHPDoc for custom magic methods
This should resolve your issue with VS Code not recognizing inherited methods like $this->user, $this->input, etc.
Let me know if you need more help!