Laravel 5.2 redirect back with success message
You should remove web
middleware from routes.php
. Adding web
middleware manually causes session and request related problems in Laravel 5.2.27 and higher.
If it didn't help (still, keep routes.php
without web middleware), you can try little bit different approach:
return redirect()->back()->with('message', 'IT WORKS!');
Displaying message if it exists:
@if(session()->has('message'))
<div class="alert alert-success">
{{ session()->get('message') }}
</div>
@endif
Controller:
return redirect()->route('subscriptions.index')->withSuccess(['Success Message here!']);
Blade
@if (session()->has('success'))
<div class="alert alert-success">
@if(is_array(session('success')))
<ul>
@foreach (session('success') as $message)
<li>{{ $message }}</li>
@endforeach
</ul>
@else
{{ session('success') }}
@endif
</div>
@endif
You can always save this part as separate blade file and include it easily. fore example:
<div class="row">
<div class="col-md-6">
@include('admin.system.success')
<div class="box box-widget">
you can use this :
return redirect()->back()->withSuccess('IT WORKS!');
and use this in your view :
@if(session('success'))
<h1>{{session('success')}}</h1>
@endif