only('username', 'password'); // grab credentials from the request try { if (!$token = JWTAuth::attempt($credentials)) { // attempt to verify the credentials and create a token for the user return response()->json(['error' => 'invalid_credentials'], 401); } } catch (JWTException $e) { return response()->json(['error' => 'could_not_create_token'], 500); // something went wrong whilst attempting to encode the token } return response()->json(['token' => "Bearer $token"]); } } ?>