Laravel Delete/Forget Cookie not working

风格不统一 提交于 2020-01-04 04:37:09

问题


How do you a delete cookies in Laravel. This is not working:

public function logout(Request $request)
{

    $this->guard()->logout();

    $request->session()->flush();

    $request->session()->regenerate();

    Cookie::queue(Cookie::forget('cavpad'));
    Cookie::queue(Cookie::forget('cavuser'));

    return redirect('/');

}

This works, but seems the wrong way to do it:

Cookie::queue(Cookie::make('cavpad', '', 0, null, env('APP_DOMAIN')));
Cookie::queue(Cookie::make('cavuser', '', 0, null, env('APP_DOMAIN')));

Why does the first way not work, but the second way does... btw, has nothing to do with the env()... Just added that in there...


回答1:


You can do this by using the code I provided, it's pretty much the same, but I know that this way of doing it works for me. But if you need to do it inline, this might also work for you:

Cookie::queue(
    Cookie::forget('cookieName')
);

This is how I think it should be done.




回答2:


Try redirecting like this:

return redirect('/')->withCookie(Cookie::forget('cavpad'))->withCookie(Cookie::forget('cavuser'));


来源:https://stackoverflow.com/questions/39840080/laravel-delete-forget-cookie-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!