Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

garcad's avatar

Redirect with not working

Just started playing with Laravel and even though I'm following tutorials - the with function doesn't seem to work!

return Redirect::route('projects.tasks.show', [$project->slug, $task->slug])->with('message', 'Task updated.');

The page redirects but I can't access the session variable. I have tried

session()->flash('message','TEST');

and this works fine.

Anyone else had this problem?

0 likes
22 replies
garcad's avatar

Hi thanks for replying. I have tried using the

redirect()->route('myRoute')->with('message','TEST')

rather than

Redirect::route('myRoute')->with('message','TEST')

As well as

redirect('http://myURL')->with('message','TEST')

And they all have the same problem - the page does redirect correctly, but without the session flash variable.

I did look at the documentation, but it just mentions the "with" method quickly - as if it should work out of the box!

garcad's avatar

Just realised that it's more to do with sessions not persisting!

jpitcher's avatar

garcard, I just had the same problem, what I realized is that there was a second redirect happening.

return redirect()->to('/')->with('message', 'Thank you for updating your billing information.');

Once I realized that / actually went to home I changed the code to:

return redirect()->to('/home')->with('message', 'Thank you for updating your billing information.');

And the message was actually there.

Ado666's avatar

Hi all,

It's a bit old topic but i tried almost everything and nothing worked for me except adding "->send()" at the end:

return redirect()->to('/home')->send();

Hope this help someone looking for a solution for the redirect problem.

Regards.

15 likes
abdulazizhamdan's avatar

@Ado666 Thank you so much!

Spent long time on redirect function to work but without avail, not even laravel doc mentions this!

kzenman's avatar

@Ado666 Saved me another five hours...thought I tried everything and this still works in version 8

Thanks!

Sindo's avatar

@Ado666 I was going nuts trying to solve why my redirect wasn't working. ->send() made it work. Thank you!

vincej's avatar

@ADO666 - Spent the whole day trying to fix this problem I found your post - And yes indeed it helped me ! Thanks !

nuelibikunle's avatar

This thread is old, im using laravel 7.x and i just bumped on this. adding the send() after the chains made it work. Thanks for this @ado666

1 like
hems's avatar

Hello, every one just resolved this issue in Laravel 7 (Redirecting With Flashed Session Data ). let me know if still someone struggling to solve this issue.

WAL30's avatar

Hello,

Same problem here, if I use Session::put('message', 'Test'), it's working but remain forever in front end after session::put I have return redirect('/') and it shows me the message but with "with" not working in laravel 8

Argolian's avatar

Had the same issue in Laravel 10.19 Could not understand why

return redirect()->route("install",['s'=>2])

Was not working, but

return redirect()->route("install",['s'=>2])->send();

works perfectly.

As someone mentioned previously, this solution isn't mentioned in the manuals.

1 like
montrealinthefall's avatar

@ado666 ->send() also worked for me to fix this issue, still working in laravel 10. you saved me so much time, thank you

Please or to participate in this conversation.