lundi 20 juillet 2020

Laravel - Delete Cookie in Middleware

I have a middleware in my project that call in every request. It will check if Request has a specific cookie, then delete another cookie. But it seems Cookies are not forgotten or set in Laravel until return in the response. something like return response('view')->withCookie($cookie); that is not possible in middlewares.

Also I tried Cookie::queue(Cookie::forget('myCookie')); nothing happened and cookie is shown in my browser.

This is my middleware handle method:

public function handle(Request $request, Closure $next)
{
    if (! $request->cookie('clear_token')) {
        cookie()->forget('access_token');                 # not worked
        Cookie::queue(Cookie::forget('access_token'));    # not worked
    }

    return $next($request);
}


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire