Send redirect and set cookie using laravel 5

I wrote this code that sets a cookie in a client browser and then redirects the client to the "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 does not request a "home" route enter image description here

how can I do both by setting a cookie and redirecting the user?

+6
source share
1 answer

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

Of course, you can use the chain to do more things in both L4 and L5.

L4: return Redirect::to('home')->withCookie($cookie);

L5: return redirect('home')->withCookie($cookie);

+21
source

Source: https://habr.com/ru/post/988242/


All Articles