問題描述
我想在 Laravel 5 中獨(dú)立設(shè)置 cookie
I want to set cookies in Laravel 5 independently
即不想使用
return response($content)->withCookie(cookie('name', 'value'));
我只想在某個頁面中設(shè)置 cookie 并在其他頁面中檢索
I just want to set cookie in some page and retrieve in some other page
創(chuàng)作可以這樣
$cookie = Cookie::make('name', 'value', 60);
但是我如何在某些控制器中檢索這些 cookie 呢?
But how can i retrieve those cookies in some controller itself ?
推薦答案
你可以試試這個:
Cookie::queue($name, $value, $minutes);
這將使 cookie 排隊(duì)以供稍后使用,稍后將在響應(yīng)準(zhǔn)備好發(fā)送時將其添加到響應(yīng)中.您可以在 Laravel
網(wǎng)站上查看文檔.
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');
<小時>
注意:如果您在當(dāng)前請求中設(shè)置了 cookie,那么您將能夠在下一個后續(xù)請求中檢索它.
這篇關(guān)于如何在控制器內(nèi)部獨(dú)立地在 Laravel 5 中設(shè)置 cookie的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!