I am trying to implement flash messages using sessions, but cannot do this.
In my controller, I:
public function store(Request $request) { session()->flash('donald', 'duck'); session()->put('mickey', 'mouse'); return redirect()->action(' CustomerController@index ')->with('bugs', 'bunny'); }
But when I check the session variables in the view, I can only see the values from session()->put('mickey', 'mouse') .
Session:
{"_token":"F6DoffOFb17B36eEJQruxvPe0ra1CbyJiaooDn3F","_previous":{"url":"http:\/\/localhost\/customers\/create"},"flash":{"old":[],"new":[]},"mickey":"mouse"}
Many people have encountered this problem without having the proper routes inside the middleware. I did it too, but it still won't work.
In routes.php:
Route::group(['middleware' => ['web']], function () { Route::get('/', function () { return view('welcome'); }); Route::get('/customers', ' CustomerController@index '); Route::get('/customers/create', ' CustomerController@create '); Route::post('/customers', ' CustomerController@store '); });
In Kernel.php:
protected $middlewareGroups = [ 'web' => [ \App\Http\Middleware\EncryptCookies::class, \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class, \Illuminate\Session\Middleware\StartSession::class, \Illuminate\View\Middleware\ShareErrorsFromSession::class, \App\Http\Middleware\VerifyCsrfToken::class, ], 'api' => [ 'throttle:60,1', ], ];
Can someone tell me what I can do wrong here? Thanks!