vscode-intelephense icon indicating copy to clipboard operation
vscode-intelephense copied to clipboard

Laravel custom FormRequest undefined methods

Open martinbean opened this issue 1 year ago • 35 comments

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.

martinbean avatar Mar 19 '25 14:03 martinbean

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?

bmewburn avatar Mar 19 '25 22:03 bmewburn

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.

martinbean avatar Mar 20 '25 11:03 martinbean

Here’s an example:

Screenshot

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):

  • StoreProductRequest extends Illuminate\Foundation\Http\FormRequest
    • Illuminate\Foundation\Http\FormRequest extends Illuminate\Http\Request
      • Illuminate\Http\Request has the route method (with public visibility)

martinbean avatar Mar 20 '25 14:03 martinbean

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?

bmewburn avatar Mar 20 '25 21:03 bmewburn

Does it still find route if 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:

Screenshot

Any changes to files.exclude or intelephense.files.exclude?

No. I’ve not changed any Intelephense-related settings in some time.

Are there multiple definitions for FormRequest or Request in the workspace?

No. I’m just extending Laravel’s.

martinbean avatar Mar 21 '25 13:03 martinbean

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?

bmewburn avatar Mar 21 '25 22:03 bmewburn

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?

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?

martinbean avatar Mar 22 '25 13:03 martinbean

Having the exact same problem. All of sudden it's showing a lot of undefined methods. I'm using laravel 12.

Image

Golveira avatar Mar 25 '25 17:03 Golveira

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.

jrebs avatar Mar 25 '25 17:03 jrebs

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.

Image

Image

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

cmcknz77 avatar Mar 28 '25 03:03 cmcknz77

I can confirm the same problem on Laravel 12.

mattkingshott avatar Mar 29 '25 12:03 mattkingshott

Please check if 1.14.4 resolves this.

bmewburn avatar Apr 01 '25 03:04 bmewburn

@bmewburn Just updated to 1.14.4 and it is still there :(

mattkingshott avatar Apr 01 '25 08:04 mattkingshott

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

Image

ivanaparicio avatar Apr 01 '25 15:04 ivanaparicio

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.

bmewburn avatar Apr 01 '25 22:04 bmewburn

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 :)

mattkingshott avatar Apr 02 '25 07:04 mattkingshott

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

lucasvmds avatar Apr 02 '25 13:04 lucasvmds

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:

Image

Image

sebj54 avatar Apr 02 '25 15:04 sebj54

@bmewburn Yeah, I’m using the laravel-ide-helper package in my projects.

martinbean avatar Apr 02 '25 22:04 martinbean

@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:

Screenshot

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:

Screenshot

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.

martinbean avatar Apr 03 '25 12:04 martinbean

Good discovery @martinbean.

Other than editing the file, did you find a way to prevent it being generated twice?

mattkingshott avatar Apr 03 '25 16:04 mattkingshott

@martinbean , nice find! As a workaround you should be able to add an entry to intelephense.files.exclude for that file.

bmewburn avatar Apr 03 '25 20:04 bmewburn

@bmewburn would that not prevent it from being added at all (rather than being duplicated)?

mattkingshott avatar Apr 03 '25 22:04 mattkingshott

@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.

bmewburn avatar Apr 03 '25 22:04 bmewburn

I think the official Laravel extension creates this folder inside vendor and it somehow messes up the file references

Image

Doing the following fixed it for me:

  • Uninstall the official Laravel extension for VS Code
  • Delete the vendor folder
  • composer install

zrfvnzr avatar Apr 04 '25 08:04 zrfvnzr

I think the official Laravel extension creates this folder inside vendor and it somehow messes up the file references

Image

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?

mattkingshott avatar Apr 04 '25 08:04 mattkingshott

@zrfvnzr Oh, so the issue is with the official Laravel VS Code plugin and not the Laravel IDE Helper plugin?

martinbean avatar Apr 04 '25 11:04 martinbean

I think the official Laravel extension creates this folder inside vendor and it somehow messes up the file references Image 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?

The undefined method errors come back when I reinstall the Laravel extension so I just stopped using it

zrfvnzr avatar Apr 04 '25 11:04 zrfvnzr

@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

zrfvnzr avatar Apr 04 '25 11:04 zrfvnzr

What if we told intelliphense to exclude that folder? 🤔

mattkingshott avatar Apr 04 '25 11:04 mattkingshott