Laravel custom FormRequest undefined methods
Intelephense is throwing lots of false positives of undefined methods. It seems it no longer “sees” methods from parent classes.
For example, given an instance of a form request class in a Laravel, it’s now throwing “Undefined method” errors when trying to use methods such as input or route, despite those methods existing in the inheritance tree (my form request extends Laravel’s built-in FormRequest class, which extends Laravel’s Request class, that contains the route method.
I‘ve tried re-indexing my workspace but that has not fixed the issue.
Which laravel version? I can't reproduce this in 10 or 11. Is there multiple definitions of any of the classes in the inheritance tree in the code base?
Laravel 12, and it’s an existing project. As in, I’ve been working on this project for a couple of weeks now, but it’s only the last ~24 hours that Intelephense has started reporting methods as being undefined.
Here’s an example:
My StoreProductRequest class extends Laravel’s default FormRequest class, but Intelephense tells me the route method does not exist (but it does, on the Request class):
-
StoreProductRequestextendsIlluminate\Foundation\Http\FormRequest-
Illuminate\Foundation\Http\FormRequestextendsIlluminate\Http\Request-
Illuminate\Http\Requesthas theroutemethod (withpublicvisibility)
-
-
Does it still find route if you go to definition on the underlined method name? Or still show hover info? Any changes to files.exclude or intelephense.files.exclude? Are there multiple definitions for FormRequest or Request in the workspace?
Does it still find
routeif you go to definition on the underlined method name?
No, because it’s saying it’s undefined, so I’m unable to Cmd + click to go to the definition.
Or still show hover info?
Just that it’s an undefined method:
Any changes to
files.excludeorintelephense.files.exclude?
No. I’ve not changed any Intelephense-related settings in some time.
Are there multiple definitions for
FormRequestorRequestin the workspace?
No. I’m just extending Laravel’s.
I created a new laravel 12 app and still cant reproduce this. Is there any errors in the output tab when selecting intelephense in the drop down? If you open the laravel Request file does it then recognise route in your custom request?
Is there any errors in the output tab when selecting intelephense in the drop down? If you open the laravel
Requestfile does it then recogniseroutein your custom request?
Just opened it and this is the output:
[Info - 13:10:19] Initialising intelephense 1.14.3
[Info - 13:10:19] Reading state from /Users/martin/Library/Application Support/Code/User/workspaceStorage/5b87c2d8a7955b0f72cc9fc5baa7209e/bmewburn.vscode-intelephense-client/7e0ca920.
[Info - 13:10:19] Intelephense premium features enabled.
[Info - 13:10:19] Initialised in 713 ms
[Info - 13:10:19] Searching file:///Users/martin/.vscode/extensions/bmewburn.vscode-intelephense-client-1.14.3/node_modules/intelephense/lib/stub for files to index.
[Info - 13:10:19] Searching file:///Users/martin/Sites/new.cms.yourfightsite.com for files to index.
[Warn - 13:10:20] file:///Users/martin/Sites/new.cms.yourfightsite.com/vendor/composer/autoload_classmap.php is over the maximum file size of 1000000 bytes.
[Warn - 13:10:20] file:///Users/martin/Sites/new.cms.yourfightsite.com/vendor/composer/autoload_static.php is over the maximum file size of 1000000 bytes.
[Warn - 13:10:20] file:///Users/martin/Sites/new.cms.yourfightsite.com/vendor/aws/aws-sdk-php/src/data/ec2/2016-11-15/api-2.json.php is over the maximum file size of 1000000 bytes.
[Warn - 13:10:20] file:///Users/martin/Sites/new.cms.yourfightsite.com/vendor/fakerphp/faker/src/Faker/Provider/nl_BE/Text.php is over the maximum file size of 1000000 bytes.
[Info - 13:10:20] Indexing started.
[Info - 13:10:20] Indexing ended. 13 files indexed in 0s.
[Info - 13:10:20] Writing state to /Users/martin/Library/Application Support/Code/User/workspaceStorage/5b87c2d8a7955b0f72cc9fc5baa7209e/bmewburn.vscode-intelephense-client/7e0ca920.
[Info - 13:10:21] Indexing started.
[Info - 13:10:21] Wrote state in 0.9s.
[Info - 13:10:21] Indexing ended. 4 files indexed in 0s.
The line(s) that stick out for me are the ones about the autoload files being over the maximum file size.
Am I guessing Intelephense isn’t picking up methods because it can’t index the project entirely?
Having the exact same problem. All of sudden it's showing a lot of undefined methods. I'm using laravel 12.
Same issue here, though based on one comment suggestion, I have found that if you disable Intelephense, reload vscode, then re-enable Intelephense, it seems to clear the issue up for a while. Eventually it resurfaces, though, and I've yet to pick up on a commonality that might indicate when/why it's doing it again.
I stumbled across this exact issue two days ago when I updated from 1.12.6 to 1.14.3 and I resolved the issue by rolling back to v1.12.6.
The moment I update to v1.14.0 or higher, intelephense starts declaring all core functions as if they cannot be resolved.
I've hovered over the 'usleep()' to show the error but literally the only difference here is that I've briefly re-updated to 1.14.3 to demonstrate, and you can see that 'trim()' is also highlighted on line 99 as is 'str_replace()' on line 83 (which you can't see because the 'usleep()' error dialog is in the way).
I can confirm the same problem on Laravel 12.
Please check if 1.14.4 resolves this.
@bmewburn Just updated to 1.14.4 and it is still there :(
I have the same issue in Laravel 9. Today, I suddenly encountered the problem where it can’t find the definition of $this->merge(), $this->input(), or $this->[property_name], and this happens with all Form Requests
Are the laravel users experiencing this using https://github.com/barryvdh/laravel-ide-helper ? Or using some other package that might be providing a polyfill or ide helper definition for FormRequest or Request? I can't reproduce the problem but it seems like there could be multiple definitions for Request in the workspace which might be breaking the type heirarchy.
I am using the ide helper, however I also had this on the same project before adding the helper. I added it to see if it would help :)
Today my extension was updated to version 1.14.4, but the errors persist. I tried reindexing the workspace and reloading the window, but with no results.
VSCode Info Version: 1.98.2 (user setup) Commit: ddc367ed5c8936efe395cffeec279b04ffd7db78 Date: 2025-03-12T13:32:45.399Z Electron: 34.2.0 ElectronBuildId: 11161602 Chromium: 132.0.6834.196 Node.js: 20.18.2 V8: 13.2.152.36-electron.0 OS: Windows_NT x64 10.0.26100
I am having the same issue. Everything was fine until I restarted VSCode (I think the extension got updated at this moment). I updated my Composer dependencies days ago so I don't think that an external package is causing the issue.
I am also using laravel-ide-helper and I have macros on Request.
Also, it seems that only FormRequest is affected by this issue, not Request:
@bmewburn Yeah, I’m using the laravel-ide-helper package in my projects.
@bmewburn So I think the issue is multiple definitions of the same file.
I’ve just noticed when going to import the Illuminate\Http\Request class in a file, that there were two suggestions:
If I pick the second option (the one that has the interface-like icon), then it takes me to a stub-like file that seems to have been created by the laravel-ide-helper package, and only contains a single method definition for the user method:
So I’m guessing it’s this stub file Intelephense is building its definitions from, and why it thinks methods like input etc don’t exist.
Good discovery @martinbean.
Other than editing the file, did you find a way to prevent it being generated twice?
@martinbean , nice find! As a workaround you should be able to add an entry to intelephense.files.exclude for that file.
@bmewburn would that not prevent it from being added at all (rather than being duplicated)?
@mattkingshott , correct. It's probably breaking the type heirarchy because when a lookup for Illuminate\Http\Request is done it is finding that definition instead of the real definition.
I think the official Laravel extension creates this folder inside vendor and it somehow messes up the file references
Doing the following fixed it for me:
- Uninstall the official Laravel extension for VS Code
- Delete the vendor folder
- composer install
I think the official Laravel extension creates this folder inside
vendorand it somehow messes up the file references
Doing the following fixed it for me:
- Uninstall the official Laravel extension for VS Code
- Delete the vendor folder
- composer install
Are you able to reinstall the extension after and have it work?
@zrfvnzr Oh, so the issue is with the official Laravel VS Code plugin and not the Laravel IDE Helper plugin?
I think the official Laravel extension creates this folder inside
vendorand it somehow messes up the file referencesDoing the following fixed it for me:
- Uninstall the official Laravel extension for VS Code
- Delete the vendor folder
- composer install
Are you able to reinstall the extension after and have it work?
The undefined method errors come back when I reinstall the Laravel extension so I just stopped using it
@zrfvnzr Oh, so the issue is with the official Laravel VS Code plugin and not the Laravel IDE Helper plugin?
I guess so. I never installed/used that laravel-ide-helper package from barryvdh
What if we told intelliphense to exclude that folder? 🤔