Mech Mech - 6 months ago 12
PHP Question

I am using laravel 5. I am using flash messaging, it is not working

My code like below!

Controller:

use Session;

public function update($id, Request $request)
{
$book = Section::findOrFail($id);
$input = $request->all();

$book ->fill($input)->save();

Session::flash('message', 'Book successfully updated!');
return redirect()->back();

}


And below is my Template file code :

@if(Session::has('message'))
<div class="alert alert-primary fade in">
<button data-dismiss="alert" class="close"><span>×</span></button>
{{ Session::get('message') }}
</div>
@endif


i am beginner for
laravel
. In controller i already use
Session
and then using
Session::flash('key','value')
, and in template file i get it using
Session::get()
method.

Answer

I was able to get it working by placing the route within the "web" middleware in route file:

Route::group(['middleware' =>['web'], 'prefix' => 'admin'], function () {   
    Route::resource('book', 'BookController');
});

After adding middleware web it works fine!

Comments