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

mchiasson's avatar

Can't get Message to be sent with Redirect

Hi everyone, having a super annoying thing happening trying to send Success messages when redirecting. I've browsed tons of similar questions on here but not found any answers.

At the end of my POST controller action I attempt to process the below code to send it back to my GET page. Ideally since it succeeds to that point it will display a message.

return redirect()->route('AddNewDocument')->with('message', 'This is a Success Message!');

Here is my blade view

@if(isset($message))
                <div class="alert alert-success">
                    {{ $message }}
                </div>
            @endif

Any ideas? If I submit it as

return redirect('/admin/documents/add')->withErrors(['errors', 'This is a Success Message']);

it will successfully pass to my error part of my view. I've also tried working with Sessions with no luck!

0 likes
3 replies
mchiasson's avatar

When placing the following in my view

 <?php echo '<pre>';var_dump(session()->all()); ?>

It returns

array (size=6)
  '_token' => string 'HDKkFo2JRNj9IN26WLuDP0jYogRX1Q3WoL0gxt6Z' (length=40)
  '_flash' => 
    array (size=2)
      'old' => 
        array (size=1)
          0 => string 'Message' (length=7)
      'new' => 
        array (size=0)
          empty
  '_previous' => 
    array (size=1)
      'url' => string 'http://homestead3.test/admin/documents/add' (length=42)
  'url' => 
    array (size=0)
      empty
  'login_web_59ba36addc2b2f9401580f014c7f58ea4e30989d' => int 1
  'Message' => string 'This is a Success Message' (length=25)

It looks like the Message variable is there, now sure why it won't display with

{{$message}}
mchiasson's avatar
mchiasson
OP
Best Answer
Level 1

Ok so looks like that is part of my 'Session' array anyways. So I got it to display by using this. Leaving this up here for anyone else to find helpful!

@if(Session::get('Message'))
                <div class="alert alert-success">
                    {{ Session::get('Message') }}
                </div>
            @endif 

Please or to participate in this conversation.