How to set cookies in laravel 5 independently inside controller(如何在控制器内部独立地在 Laravel 5 中设置 cookie)
问题描述
我想在 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在控制器内部独立地在 Laravel 5 中设置 cook
基础教程推荐
- 如何在 Laravel 中使用 React Router? 2022-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- 如何替换eregi() 2022-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
