Laravel请求cookie不';不显示JS创建的Cookie

Laravel请求cookie不';不显示JS创建的Cookie,laravel,laravel-5,Laravel,Laravel 5,我正在使用通过前端设置Cookie。 为什么我不能在我的Laravel 5.8应用程序中通过以下方式访问它: dd(请求()->cookies)?Cookie名称可见,但值为null。但是,当我尝试通过“正常”方式获取Cookie的值时,我确实得到了值:dd($\u Cookie['the-Cookie-Value-I-want') 如何通过“Laravel方式”访问Cookie的值?哪个更安全。只有由laravel创建的cookie才能由laravel处理。 下面是实现这一目标的方法 转到:a

我正在使用通过前端设置Cookie。 为什么我不能在我的Laravel 5.8应用程序中通过以下方式访问它:
dd(请求()->cookies)
?Cookie名称可见,但值为null。但是,当我尝试通过“正常”方式获取Cookie的值时,我确实得到了值:
dd($\u Cookie['the-Cookie-Value-I-want')


如何通过“Laravel方式”访问Cookie的值?哪个更安全。

只有由laravel创建的cookie才能由laravel处理。

下面是实现这一目标的方法

转到:app>Http>Kernal.php:在下$middlewareGroups数组下,对此进行评论

 'web' => [
            //\App\Http\Middleware\EncryptCookies::class,
然后试试看

这是演示

<!doctype html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>Laravel</title>
    </head>
    <body>
        {{  Cookie::get('cookie1') }}
        {{  request()->cookie('cookie1') }}
        <script type="text/javascript">
            document.cookie = 'cookie1=test; path=/'
        </script>
    </body>
</html>

拉维尔
{{Cookie::get('cookie1')}
{{request()->cookie('cookie1')}
document.cookie='cookie1=测试;路径=/'

我知道这是一个老问题,但您可以禁用特定cookie的加密,而不是禁用所有cookie的加密(这会破坏安全会话)

编辑
\App\Http\Middleware\EncryptCookies
类以包括以下内容:

/**
 * The names of the cookies that should not be encrypted.
 *
 * @var array
 */
protected $except = [
    'my_frontend_cookie_name'
];

您现在可以通过
request()->cookie()
cookie::get()
facade来访问cookie值。

可能是因为laravel cookie是加密的。请参见相关问题中显示的答案。