You need to get the data from session. $errors is a special case and Laravel makes sure there is always an errors object available in the view.
check https://laravel.com/docs/5.4/redirects#redirecting-with-flashed-session-data
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi everyone, I'm working on a project and can return errors to my views not a problem, however when attempting to return other variables like 'message', it just does not work for me.
I am trying right now on my Post function within a controller to do this
return redirect()->back()->withMessage('IT WORKS!');
and in my view I have
@if ($errors->any())
<div class="alert alert-danger">
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
@if(isset($message))
<div class="alert alert-success">
{{ $message }}
</div>
@endif
However when it redirects back to the regular page it does not list my Message. Normal view pages are doing this fine just not on these redirect ones. If I populate an error variable it works fine using
->withErrors('Help this is an Error!')
This is on Laravel 5.4 and I'm not adding the Web middleware onto my routes page. Thanks for any help.
Create a file in views. Eg: flashMessage.blade.php. and inside of it do.
@if (Session::has('success'))
{{ Session::get('success') }}
@endif
Now in your controller :
return back()->with('success', 'Your success message')->withErrors();
In your views :
@include('flashMessage')
Please or to participate in this conversation.