vendredi 29 avril 2016

Laravel 5.2 Flash Issue with Redirect & Middleware

I currently have two set of codes , one works well with Session/Flash one doesn't.

Basically a Signup/Login form has got no issue displaying Flash , but they are not under any middleware.

Route::get('signup', ['uses' => 'HomeController@signup']);
Route::post('signup', ['uses' => 'HomeController@postSignup']);
Route::get('login', ['uses' => 'HomeController@login']);
Route::post('login', ['uses' => 'HomeController@postLogin']);

Things starts to get tricky when i started applying web & auth middleware to a group of code.

Route::group(['middleware' => ['web','auth']], function () {
Route::post('claimForm', ['uses' => 'HomeController@claimForm']);
}

The problem with this claim form is , the flash will be dropped if I do a redirect.

   $request->session()->flash('pass', 'Claim Submitted!');
    return redirect('/dashboard');

BUT if i do a return VIEW instead of redirect, the flash works perfectly fine.

I tried to remove web from middleware , now the flash will stay at a few pages, random timing and frequency each time I submit.

  • I tried to remove the whole middleware, things started to work normally. The flash will only happen once. Without the Web& Auth middleware.

I cant afford to not have middleware , so please advice. I have 3 Route::groups.With middleware inplace, I tried to re-flash on the GET which the POST is redirecting to but it also wont work.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire