Answer the question
In order to leave comments, you need to log in
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']);
});
});
?>
session()->flash('message');
@if (session()->has('message'))
{{ session()->get('message') }}
@endif
Answer the question
In order to leave comments, you need to log in
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 questionAsk a Question
731 491 924 answers to any question