user6122500
user6122500

Reputation: 942

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

I've been using cookies in my Laravel 5.1 app successfully; 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.

Here's the relevant code in the controller; the $condn variable ends up being empty. 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');       
}

Upvotes: 2

Views: 837

Answers (1)

user6122500
user6122500

Reputation: 942

I've realised that it's because in app/http/Kernel, I had the following code; 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

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,
    ];

Upvotes: 1

Related Questions