Session message is not working i tried this code and many fix available online Here id my store function `
public function store(Request $request)
    {
        // dd($request->all());
        $this->validate($request, [
            'name'      =>'required',
            'username'  =>'required',
            'email'     =>'required',
            'address'   =>'required',
            'likes'     =>'required',
            'gender'        =>'required'
        ]);
        $input = $request->all();
        Contacts::create($input);
        Session::put('flash_message', 'Task successfully added!');
        return redirect()->back();
    }
And Retrieving by this code
@if(Session::has('flash_message'))
        <div class="alert alert-success">
            {{ Session::get('flash_message') }}
        </div>
@endif
                I resolved issue with laravel 6.x
As soon as I moved \Illuminate\Session\Middleware\StartSession::class and \Illuminate\View\Middleware\ShareErrorsFromSession::class from web $middlewareGroups to $middleware in app\Http\Kernel.php  everything started working as expected.
I Resolved the Issue with laravel 5.2.
I was having route like this
Route::group(['middleware' => [ 'web','auth']], function () {
.......
}
So Removed the web middle ware
Route::group(['middleware' => ['auth']], function () {
.......
}
and its start working
Analysis: By default Laravel Add web Middleware. check by php artisan route:list it shows web, web,auth .
so by defining it again redirect two time for the web middleware.
I RESOLVED the issue with laravel 5.2.
I was having all the routes inside this:
Route::group(['middleware' => 'web'], function() {
I remove it because when I used the command php artisan route:list in the Name Middleware column the "web" shows to times: web, web.
If you have AUTH replace by:
Route::group(['middleware' => 'auth'], function() {
Also I delete a duplicate route (in routes.php). Now I just have:
Route::resource('/publicaciones', 'PublicacionesController');
My controller:
return redirect()->back()->with('success', 'Saved!'); 
My view:
  @if(Session::has('success'))
          <div class="alert alert-success">
              {{ Session::get('success') }}
          </div>
  @endif
                        have you include the following namespace
use Session;
instead of the following code
 Session::put('flash_message', 'Task successfully added!'); 
use
 Session::flash('flash_message', 'Task successfully added!');
in instead to
return redirect()->back();
try using
 return redirect()->route('your route');
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With