問題描述
我想在 Laravel 5 中獨立設置 cookie
I want to set cookies in Laravel 5 independently
即不想使用
return response($content)->withCookie(cookie('name', 'value'));
我只想在某個頁面中設置 cookie 并在其他頁面中檢索
I just want to set cookie in some page and retrieve in some other page
創作可以這樣
$cookie = Cookie::make('name', 'value', 60);
但是我如何在某些控制器中檢索這些 cookie 呢?
But how can i retrieve those cookies in some controller itself ?
推薦答案
你可以試試這個:
Cookie::queue($name, $value, $minutes);
這將使 cookie 排隊以供稍后使用,稍后將在響應準備好發送時將其添加到響應中.您可以在 Laravel
網站上查看文檔.
This will queue the cookie to use it later and later it will be added with the response when response is ready to be sent. You may check the documentation on Laravel
website.
更新(檢索 Cookie 值
):
$value = Cookie::get('name');
<小時>
注意:如果您在當前請求中設置了 cookie,那么您將能夠在下一個后續請求中檢索它.
這篇關于如何在控制器內部獨立地在 Laravel 5 中設置 cookie的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!