我想在 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模板网!
Laravel Eloquent Union 查询Laravel Eloquent Union query(Laravel Eloquent Union 查询)
覆盖 Laravel 5 辅助函数Overwrite laravel 5 helper function(覆盖 Laravel 5 辅助函数)
laravel querybuilder 如何在 where 函数中使用 likelaravel querybuilder how to use like in wherein function(laravel querybuilder 如何在 where 函数中使用 like)
响应内容必须是实现 __toString()、“boolean"和“The Response content must be a string or object implementing __toString(), quot;booleanquot; given after move to psql(响应内容必须是实现 __toS
Laravel 5 的角色,如何只允许管理员访问某些根Roles with laravel 5, how to allow only admin access to some root(Laravel 5 的角色,如何只允许管理员访问某些根)
Laravel Auth - 使用 md5 而不是集成的 Hash::make()Laravel Auth - use md5 instead of the integrated Hash::make()(Laravel Auth - 使用 md5 而不是集成的 Hash::make())