'Method Illuminate\Auth\SessionGuard::users does not exist

I'm having a problem with Auth. I'm just learning about Laravel, I'm doing login. I don't know how to fix it it says:

Method Illuminate\Auth\SessionGuard::users does not exist.

this is my code in login function

public function getlogin(Request $request){

  $this->validate($request, [
    'email'=> 'required|max:32',
    'password'=> 'required|max:32|min:8',
  ]);
  if (Auth::attempt(['email'=>$request->email,'password'=>$request->password])) {
    $user = users::where('email','=',$request->email)->first();
    return redirect('/messenger')->with('usersignin');
  }
  return "ooopps something wrong";

}

and this is where the name from the database will be display

<div class="">
          <h1>Welcome
            @if(session('user'))
              {{session('user')}}
            @elseif(session('usersignin'))
              {{ucwords(Auth::users()->fname)}}
            @endif</h1>
        </div>


Solution 1:[1]

You need to use user instead of users, user is provided with Auth and will get the current logged in user id.

$id = \Auth::user()->id;

Or you want to get the user

$user = \Auth::user();

Solution 2:[2]

I solved this error by running the below command

php artisan jwt:secret
php artisan cache:clear
php artisan config:cache

Solution 3:[3]

in your if statement just use it as below

if (auth()->attempt(['email'=>$request->email,'password'=>$request->password])) {
    $user = users::where('email','=',$request->email)->first();
    return redirect('/messenger')->with('usersignin');
  }

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 dexhunter
Solution 2 riju
Solution 3 Khaldoun Al Halabi