Framework: [5.2] Session::flash() doesn't works any more for laravel 5.2 (USING AJAX)

Created on 2 Feb 2016  路  12Comments  路  Source: laravel/framework

Well this is the problem.

For example.

Controller side

public function foo()
{
      // do somthing
      Session::flash('status','Foobar');

      return URL::to(......);
}

javascript

$.ajax({
   .
   .
   .
  success:function(response){
      window.location.replace(response)
  }

})

view side

        @if (session('status'))
           <p>{{ session('status') }}</p>
         @endif

for Laravel 5.2.* it's not showing anything . instead it's works using Laravel 5.1

Most helpful comment

@Jayaramvenkatanarayanan
make sure all routes uses web middleware

Route::group(['middleware' => 'web'], function () {
// routes here

});

All 12 comments

make sure all routes uses web middleware
Route::group(['middleware' => 'web'], function () {
// routes here
Route::get('/login', 'Auth\AuthController@showLoginForm')->name('login');

});

@mohamedsharaf Thanks

welcome keep not also auth routes should be within web otherwise u will not be aable to get Auth::user()

this also know as
laravel 5.2 login not working after redirect

@mohamedsharaf yes you'r right.
but I want to know did middleware (web) by default exist right laravel 5.1 ?
cuz we might got problems when we develop laravel packages supporting (5.1, 5.2)

groups of middleware is new in 5.2
open kernal.php for both version and u will get it

open kernal.php for both version and u will get it

It's not really the same time of thing though, since the groups are run by the routing layer, but the global middleware wrap around that entire layer from the outside.

@amranidev
@GrahamCampbell sorry for double mention

i tried to make it works for both version but 5.2 miss some function
https://github.com/laravel/framework/issues/12141

I am also in same situation, i have request to store the data. My data's are stored but i have tried to show the flash message but i did not get that (also laravel/flash )...

Pl help me

@Jayaramvenkatanarayanan
make sure all routes uses web middleware

Route::group(['middleware' => 'web'], function () {
// routes here

});

Thanks now its work on me !!!!!

Thanks & Regards,
Jayaram Venkatanarayanan.


From: Amrani Houssain [email protected]
Sent: Monday, July 18, 2016 4:19 AM
To: laravel/framework
Cc: Jayaram Venkatanarayanan; Mention
Subject: Re: [laravel/framework] [5.2] Session::flash() doesn't works any more for laravel 5.2 (USING AJAX) (#12136)

@Jayaramvenkatanarayananhttps://github.com/Jayaramvenkatanarayanan
make sure all routes uses web middleware

Route::group(['middleware' => 'web'], function () {
// routes here

});

You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHubhttps://github.com/laravel/framework/issues/12136#issuecomment-233208839, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AOIbmmZRbIS6dj2iBwcxqYI6DJoUcfD1ks5qWrGAgaJpZM4HR5oM.

strange. even I use web middleware, it still not working , no flash data stored in session, then I change middleware to auth, it does the work. also strange thing is I can just get one data even I use mutiple chain with method.

my routes like this:

Route::group(['namespace' => 'Package', 'prefix' => 'package', 'middleware' => ['auth']], function () {
    Route::get('catelog/new', 'CatelogController@add');
    ....
}

set flash data:

return redirect()->back()
                ->with('page_message', 'success')
                ->with('page_code', 0);

After I successfully adding. I can only get the page_code = 0, with the auth middleware.

What I have missed?

Edit:

Laravel Framework version 5.2.41

Edit:

I'm not alone. solved by this: SO LINK, pay attention to middleware and middlewareGroups in kernel.php.

but I still can't get second flash data, I dump(session()->has('page_code')), and it prints true, I dump(session()->has('page_message')), it gives me false. I changed the way to set flash data like this (seen the source code of method with()):

return back()->with(['page_code' => 0, 'page_message' => 'success']);

Hi all,

Above laravel 5.2 without using middelware function bootstrap session messages will be work.

Thanks

Was this page helpful?
0 / 5 - 0 ratings