send redirect and setting cookie, using laravel 5

21,599

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

Share:
21,599
Salar
Author by

Salar

Software Engineer, Mostly Web... I love architecture and a good challenge to solve. Interested in Edge of tech and changing the rules of current systems, for better.

Updated on May 31, 2020

Comments

  • Salar
    Salar almost 4 years

    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?

  • Salar
    Salar almost 9 years
    then how do I set the cookie?
  • Ali Gajani
    Ali Gajani almost 9 years
    You can use chaining. See the documentation