phplaravelvisual-studio-codeintelephense

VS Code intelephense shows incorrect error: Undefined method 'save'


I'm using the intelephense v1.8.2 extension in VS Code and I'm working on a laravel project. As I get the user using Auth::user(); and call $user->save(); the intelephonse keep showing incorrect error Undefined method 'save'. Is there a way to fix this issue?

enter image description here


Solution

  • You can use @var to ignore this:

    /** @var \App\Models\User $user **/
    $user = Auth::user();
    $user->name = 'alice';
    $user->save();