mercredi 19 mai 2021

How to flash session data when redirect to intended() using Laravel?

I'm trying to redirect to the intended URL after login, and flash some session data together to show a popup modal only once.

If I do this, it works:

return redirect(RouteServiceProvider::HOME)->with('showWelcome', true);

I can retrieve the session in blade view as such:

@if (session('showWelcome'))
    // show modal..
@endif

However, if I use intended(), the session is no way to be found:

return redirect()->intended(RouteServiceProvider::HOME)->with('showWelcome', true);

I've also tried the following:

  • using the following instead of with():
$request->session()->flash('showWelcome', true);
  • using the \Session Class instead of the session() helper to retrieve the session data:
@if (\Session::has('showWelcome'))
    // show modal
@endif

Unfortunately, the problem persists where it only works when I'm not using intended().

I've searched high and low but couldn't exactly find any solution to this.

Am I doing something wrong or understanding how redirect works incorrectly?




Aucun commentaire:

Enregistrer un commentaire