Laravel删除/忘记Cookie不起作用 [英] Laravel Delete/Forget Cookie not working

查看:363
本文介绍了Laravel删除/忘记Cookie不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Laravel中删除Cookie.这不起作用:

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')));

为什么第一种方法不起作用,但是第二种方法却... btw,与env()无关...只是在其中添加了...

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...

推荐答案

尝试像这样重定向:

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

这篇关于Laravel删除/忘记Cookie不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆