Ad

Flash Session Not Working In Middleware Laravel 5.2

- 1 answer

I am newcomer in Laravel. I have a problem with session flash in Middleware. In Middleware:

public function handle($request, Closure $next)
       {
            if(auth()->check()){
                return $next($request);
            }else{
                Notification::error('Please login');
                return redirect()->route('admin.auth.login.get')->with('test',' session');
            }

        }

In View:

I get Nofitication but nothing happen. I check with flash session (session('test'))-> nothing happen.

Please help to explain me why it dont work? and what's solution?.

Thank you very much and sorry about my English.

Ad

Answer

Add your route in web middleware

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

See this
basic-routing

Make sure that in kernel.php
web Middleware is

        '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,

    ],
Ad
source: stackoverflow.com
Ad