Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

send redirect and setting cookie, using laravel 5

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 enter image description here

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

like image 705
Salar Avatar asked May 30 '15 20:05

Salar


1 Answers

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

like image 82
Ali Gajani Avatar answered Oct 26 '22 14:10

Ali Gajani