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

SoutoDev's avatar

redirecting with flashed session data is not display data

Hi, i'm trying to display a error/success message after a request, but it's not displaying, when i dump it the message is there, and the first part when i display the type of the message works properly

here's my code, need some help, guys!

return redirect()->back()->with('type', 'error')
                    ->with('message', 'try again!');
@if (session('message'))
    <div class="alert alert-{{ session('type') }}">
        {{ session('message') }}
    </div>
@endif 
    
0 likes
3 replies
robrogers3's avatar

why are you doing a redirect()->back().

just return back();

also there is no alert-error it's alert-danger (unless you have your own.)

but you are saying the 'type' works but there is message does not display?

what version of laravel are you using?

SoutoDev's avatar

hi, i have my own css so i use error.

My laravel is 5.2 is a old project and yes, i don't understand is displaying error, an empty div, when i tried to use {!! session('message') !!} the message is displayed, but without the right configuration

robrogers3's avatar

try this: return back()->with(['type' => 'success', 'message' => 'ntoehunyes!']);

Please or to participate in this conversation.