Ad

I Am Using Laravel 5. I Am Using Flash Messaging, It Is Not Working

- 1 answer

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.

Ad

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!

Ad
source: stackoverflow.com
Ad