R
R
Roman Volkov2016-04-22 16:03:36
Laravel
Roman Volkov, 2016-04-22 16:03:36

Why doesn't Flash work in Laravel 5.2?

Need to use session messages in laravel. I have routes like this:

<?php 
Route::group(['middleware' => ['web', 'locale', 'auth']], function () {


  /*========================================
  =            Роуты для админа            =
  ========================================*/

  Route::group(['namespace' => 'Admin', 'prefix' => 'admin', 'middleware' => 'web'], function() {

      	/*============================================================
      	=            Роуты для всех админитративных ролей            =
      	============================================================*/

      	Route::group(['middleware' => ['role:super_admin|admin', 'web']], function() {

      		Route::get('/', '[email protected]');
      		// Другие роуты //
      		Route::resource('users', 'UsersController', ['except' => ['destroy']]);

       });


  });

  /*=======================================================
  =            Роуты для обычных пользователей            =
  =======================================================*/

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

      Route::get('/', ['as' => 'home', 'uses' => '[email protected]']);
 			// Другие роуты //
      Route::resource('users', 'UsersController', ['only' => 'update']);

   });



});
 ?>

I call like this
session()->flash('message');
And in the template
@if (session()->has('message'))
 {{ session()->get('message') }}
@endif

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrzej Wielski, 2016-04-22
@wielski

flash only works the next time the page is opened. Let's say after a redirect to a page with a message.
Make sure this condition is met.
If you call view right away, it's better to pass the message as a variable.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question