IAmJulianAcosta
IAmJulianAcosta

Reputation: 1212

null cookie in Middleware

I'm writing a middleware to filter a request based on its cookies, but I get a null cookie.

public function handle($request, Closure $next)
{
    var_dump ($request->cookie("cookie_name"); //<------- null
    return $next($request);
}

Is this the right function to get a cookie from middleware? Why is null, if cookie exists?

Upvotes: 0

Views: 685

Answers (1)

IAmJulianAcosta
IAmJulianAcosta

Reputation: 1212

Laravel is encrypting cookies, so I had to add an exception to encrypted cookies in App\Http\Middleware\EncryptCookies\

protected $except = [
    'cookie_name'
];

Upvotes: 4

Related Questions