あなたはこれを読むかもしれません。だからあなたの場合、でApp\Api\v1\Controllers\AuthController@postLogin
:
/**
* Handle a login request to the application.
*
* @param \Illuminate\Http\Request $request
*
* @return \Illuminate\Http\Response
*/
public function postLogin(Request $request)
{
try {
$this->validate($request, [
'email' => 'required|email|max:255',
'password' => 'required',
]);
} catch (HttpResponseException $e) {
return response()->json([
'message' => 'invalid_auth',
'status_code' => IlluminateResponse::HTTP_BAD_REQUEST,
], IlluminateResponse::HTTP_BAD_REQUEST);
}
$credentials = $this->getCredentials($request);
try {
// Attempt to verify the credentials and create a token for the user
// You may do anything you like here to get user information based on credentials given
if ($user = MyFramework::validate($credentials)) {
$payload = JWTFactory::make($user);
$token = JWTAuth::encode($payload);
} else {
return response()->json([
'message' => 'invalid_auth',
'status_code' => IlluminateResponse::HTTP_BAD_REQUEST,
], IlluminateResponse::HTTP_BAD_REQUEST);
}
} catch (JWTException $e) {
// Something went wrong whilst attempting to encode the token
return response()->json([
'message' => 'could_not_create_token',
], IlluminateResponse::HTTP_INTERNAL_SERVER_ERROR);
}
// All good so return the token
return response()->json([
'message' => 'token_generated',
'token' => $token,
]);
}