I'm trying to get flash messaging to work in Laravel 5.2. Everything seems to be correct but when I go to /alert nothing happens. Any suggestions?
The following is my routes.php..
Route::group(['middleware' => ['web']], function(){
Route::get('/', [
'uses' => 'HomeController@index',
'as' => 'welcome',
]);
Route::get('/alert', function()
{
return redirect()->route('welcome')->with('info', 'You have signed up!');
});
});
The following is my alerts.blade.php...
@if (Session::has('info'))
<div class="alert">
{{ Session::get('info') }}
</div>
@endif
The following is my master.blade.php..
<!DOCTYPE html>
<html>
<head>
<title>@yield('title')</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
</head>
<body>
@include('includes.header')
<div class="container">
@yield('content')
@include('includes.alerts')
</div>
</body>
</html>
You should try to use as the documentation suggest instead of using the facade \Session
From documentation:
Of course, after the user is redirected to a new page, you may retrieve and display the flashed message from the session. For example, using Blade syntax:
@if (session('info'))
<div class="alert">
{{ session('info') }}
</div>
@endif
Your code work fine on my laravel 5.2 using the syntax above.
EDIT:
they use return redirect('dashboard')->with('status', 'Profile updated!');
they don't use the method redirect()->route()
try to use this instead:
Route::get('/alert', function(\Illuminate\Http\Request $request)
{
$request->session()->flash('info', 'You have signed up!');
return redirect()->route('welcome');
});
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments