如何在控制器内部独立地在 Laravel 5 中设置 cookie [英] How to set cookies in laravel 5 independently inside controller

查看:28
本文介绍了如何在控制器内部独立地在 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆