使用laravel 5发送重定向和设置cookie [英] send redirect and setting cookie, using laravel 5
本文介绍了使用laravel 5发送重定向和设置cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经编写了这段代码,该代码在客户端的浏览器中设置一个cookie,然后必须将客户端重定向到本地"路由,
I have written this code, that sets a cookie in client's browser, and after that must redirect the client to 'home' route,
$response = new Response();
$response->withCookie(cookie()->forever('language', $language));
$response->header('Location' , url('/home')) ;
return $response ;
客户端收到这些标头,但客户端未请求本地"路由
the client receives these headers but the client doesn't make request for the "home" route
我应该同时设置Cookie和重定向用户吗?
how should I do both, setting the cookie and redirect the user?
推荐答案
为什么不做return Redirect::to('home');
当然,在L4和L5中,您都可以使用链接来做更多的事情.
Of course you can use chaining to do more things, both in L4 and L5.
L4:return Redirect::to('home')->withCookie($cookie);
L5:return redirect('home')->withCookie($cookie);
这篇关于使用laravel 5发送重定向和设置cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文