send redirect and setting cookie, using laravel 5

不羁的心 提交于 2019-12-10 03:09:21

问题


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

how should I do both, setting the cookie and redirect the user?


回答1:


Why don't you do return Redirect::to('home');

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



来源:https://stackoverflow.com/questions/30550789/send-redirect-and-setting-cookie-using-laravel-5

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