public function login(Request $request){         $fields = $request->validate([           'email'=>'required|string|email',          'password'=>'required|string'            ]);          //Check email          $user= User::where('email', $fields['email'])->first();          //Check Password         if(!$user || !Hash::check($fields['password'], $user->password) ){             return response([                 'message'=>'Invalid Credentials'             ], 401);         }          $token = $user->createToken('myapptoken')->plainTextToken;          $response= [             'user' => $user,             'token'=> $token         ];          return response($response, 201);     } 

Read more of this post