简体   繁体   English

Laravel:升级到 5.3 后无法获取 Cookie 值

[英]Laravel: Can't get Cookie value after upgrading to 5.3

I've been using cookies in my Laravel 5.1 app successfully;我一直在我的 Laravel 5.1 应用程序中成功使用 cookie; however after upgrading to 5.3, I've noticed that while I can still set cookies (can see them in the browser), I can no longer get / retrieve them.但是在升级到 5.3 之后,我注意到虽然我仍然可以设置 cookie(可以在浏览器中看到它们),但我无法再获取/检索它们。

Here's the relevant code in the controller;这是控制器中的相关代码; the $condn variable ends up being empty. $condn 变量最终为空。 Any help would be much appreciated!任何帮助将非常感激!

   use Illuminate\Http\Request;
   use Cookie;

public function addtocart(Request $request)    {
            Cookie::queue('id', Session::getId(), 50000);
}

 public function cart(Request $request)
    {
            $condn = $request->cookie('id');       
}

I've realised that it's because in app/http/Kernel, I had the following code;我意识到这是因为在 app/http/Kernel 中,我有以下代码; I deleted all of the lines except for the Maintenance one (to match the same kernel file in Laravel's git - https://github.com/laravel/laravel/blob/master/app/Http/Kernel.php ) and then it worked我删除了除维护之外的所有行(以匹配 Laravel 的 git 中的相同内核文件 - https://github.com/laravel/laravel/blob/master/app/Http/Kernel.php )然后它起作用了

protected $middleware = [
        \Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
        \App\Http\Middleware\EncryptCookies::class,
        \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
        \Illuminate\Session\Middleware\StartSession::class,
        \Illuminate\View\Middleware\ShareErrorsFromSession::class,
        \App\Http\Middleware\VerifyCsrfToken::class,
    ];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM