本文介紹了如何在 Laravel 中設(shè)置和獲取 Cookie的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
我想在 cookie 中設(shè)置和獲取值,但它不起作用:
I would like to set and get value in cookie but it doesn't work:
Cookie::queue('online_payment_id', "1", 15);
$value = Cookie::get('online_payment_id');
dd($value);
dd()
返回 null
;
我使用了以下方式,但收到此消息:
I used below way but I got this message:
Method cookie does not exist.
request()->cookie('online_payment_id');
$value = response()->cookie('online_payment_id', "1", 15);
dd($value);
推薦答案
設(shè)置 Cookies
public function setCookie(Request $request){
$minutes = 60;
$response = new Response('Set Cookie');
$response->withCookie(cookie('name', 'MyValue', $minutes));
return $response;
}
獲取 Cookie
public function getCookie(Request $request){
$value = $request->cookie('name');
echo $value;
}
這篇關(guān)于如何在 Laravel 中設(shè)置和獲取 Cookie的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!