如何在Laravel 5.4中设置cookie? [英] How to set cookie in laravel 5.4?
本文介绍了如何在Laravel 5.4中设置cookie?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在laravel 5.4中具有此功能,但无法从Cookie中获取任何信息.
I have this function in laravel 5.4 but I cant get anything from cookie.
Cookie::queue('currentLang', 'heb', 999999999);
echo $request->cookie('currentLang');
但是我得到的是一些长字符串,而不是我设置的字符串.
But I am getting some long string and not what I set.
推荐答案
Laravel具有cookie助手!
Laravel has a cookie helper!
/**
* Create a new cookie instance.
*
* @param string $name
* @param string $value
* @param int $minutes
* @param string $path
* @param string $domain
* @param bool $secure
* @param bool $httpOnly
* @return \Symfony\Component\HttpFoundation\Cookie
*/
function cookie($name = null, $value = null, $minutes = 0, $path = null, $domain = null, $secure = false, $httpOnly = true)
{
$cookie = app(CookieFactory::class);
if (is_null($name)) {
return $cookie;
}
return $cookie->make($name, $value, $minutes, $path, $domain, $secure, $httpOnly);
}
然后使用:
Cookie::get('$name')
这篇关于如何在Laravel 5.4中设置cookie?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文