bmewburn / vscode-intelephense

PHP intellisense for Visual Studio Code
https://intelephense.com
Other
1.61k stars 94 forks source link

Laravel undefined method bug. #2804

Closed nsakib176 closed 6 months ago

nsakib176 commented 7 months ago

Describe the bug In Laravel model, after creating a custom function, when I call it other than declaring the object of that class, it shows undefined method error.

To Reproduce

  1. Any Laravel Application.
  2. in migration folder, users table, add a role column. (simple admin or not)
  3. in User.php model file, create a function to check if admin. e.g. public function isAdmin() { return $this->role === 'admin'; }
  4. in any controller, add the following: auth()->user()->isAdmin()

Expected behavior it should recognize auth()->user() is a object of the User model and should not show the undefined method error

Screenshots Similar case with another method. image

Platform and version OS = windows 10 and Intelephense version = v1.10.2.

bmewburn commented 6 months ago

Here's one soln to your problem https://github.com/bmewburn/vscode-intelephense/issues/2135#issuecomment-1985272564. The helper file is just for the extension, I recommend putting it somewhere outside of the laravel project folders though.