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

查看:87
本文介绍了如何在控制器内部的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.

更新(Retrieving A Cookie Value):

$value = Cookie::get('name');


注意:如果您在当前请求中设置了cookie,则可以在下一个后续请求中检索它.

这篇关于如何在控制器内部的Laravel 5中独立设置cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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