howellmartinez howellmartinez - 2 years ago 165
PHP Question

Laravel 5.2 Session flash not working even with web middleware

I am trying to implement flash messaging using sessions but am unable to do so.

In my controller I have:

public function store(Request $request) {
session()->flash('donald', 'duck');
session()->put('mickey', 'mouse');
return redirect()->action('CustomerController@index')->with('bugs', 'bunny');

But when I check the session variables in the view, I can only see the values from
session()->put('mickey', 'mouse')



A lot of people encountered this problem by not having the relevant routes inside the web middleware. I made sure to do this as well but it still wouldn't work.

In routes.php:

Route::group(['middleware' => ['web']], function () {

Route::get('/', function () {
return view('welcome');

Route::get('/customers', 'CustomerController@index');
Route::get('/customers/create', 'CustomerController@create');
Route::post('/customers', 'CustomerController@store');

In Kernel.php:

protected $middlewareGroups = [
'web' => [

'api' => [

Can anyone let me know what I could be doing wrong here? Thanks!

Answer Source

Fixed the issue by replacing

Route::group(['middleware' => ['web']], function () {


Route::group(['middlewareGroups' => ['web']], function () {

No idea why this works though when all the documentation suggests that we use ['middleware' => ['web']]

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download