我想发送Bearer令牌并将其保存为前端的cookie。
我这样传递cookie:
return response()->json([
'remember_token' => $user->remember_token,
], 200)->withCookie(cookie('auth_token', 'random_token', 3600));
但是它根本没有设置cookie!请帮忙!
答案 0 :(得分:1)
尝试一下:
$cookie = Cookie::make('auth_token', $user->remember_token, 3600);
$response = Response::json('remember_token' => $user->remember_token, 200);
$response->headers->setCookie($cookie);
return $response;
取自this answer。