我在laravel 5.4中有这个功能,但是我无法从cookie获得任何东西。
Cookie::queue('currentLang', 'heb', 999999999);
echo $request->cookie('currentLang');
但是我得到一些长串而不是我设置的。
答案 0 :(得分:2)
Laravel有一个cookie助手!
/**
* 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')
答案 1 :(得分:2)
使用Illuminate \ Support \ Facades \ Cookie;
...
Cookie :: queue('currentLang','heb',999999999);
echo Cookie :: get('currentLang');