1public function authenticate(Request $request) {
2 $email = $request->input('email');
3 $user = User::where('email', '=', $email)->first();
4 try {
5 // verify the credentials and create a token for the user
6 if (! $token = JWTAuth::fromUser($user)) {
7 return response()->json(['error' => 'invalid_credentials'], 401);
8 }
9 } catch (JWTException $e) {
10 // something went wrong
11 return response()->json(['error' => 'could_not_create_token'], 500);
12 }
13 // if no errors are encountered we can return a JWT
14 return response()->json(compact('token'));
15}