bmewburn / vscode-intelephense

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

Undefined method 'save'.intelephense(P1013) #2883

Closed Ningthem-Singh closed 4 months ago

Ningthem-Singh commented 4 months ago
public function update_password(Request $request)
    {
        $request->validate([
            'existing_password' => 'required',
            'new_password' => 'required|min:8|confirmed',
        ]);

        $user = Auth::user();

        if (!Hash::check($request->existing_password, $user->password)) {
            return back()->withErrors(['existing_password' => 'The current password does not match our records.']);
        }

        $user->password = Hash::make($request->new_password);
        $user->save();
        Auth::logout();

        return redirect()->route('login')->with('success', 'Password changed successfully.');
    }

when i use the $user->save(); i get error saying Undefined method 'save'.intelephense(P1013) whereas the code syntax is correct as per laravel documentation. How do i remove the error being shown and also similarly when i use the hasRole() i get error

bmewburn commented 4 months ago

Auth::user() returns an interface that does not have those methods declared on it. You can use an ide helper like https://github.com/barryvdh/laravel-ide-helper or "cast" to the concrete type with an annotation.

/** @var \App\Models\User $user */
$user = Auth::user();