1

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.

liemphan
  • 23
  • 2

1 Answers1

1

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,

    ],
paranoid
  • 6,799
  • 19
  • 49
  • 86
  • Thanks for your answer quickly .I've added middle=>'web' already but it's still not working. This is my code in Route.php
    Route::group(array('middleware'=>'web'),function(){ Route::get('auth/register', array('as'=>'admin.auth.register.get','uses'=>'AuthController@getRegister')); Route::post('auth/register', array('as'=>'admin.auth.register.post','uses'=>'AuthController@postRegister')); Route::get('auth/login', array('as'=>'admin.auth.login.get','uses'=>'AuthController@getLogin')); Route::post('auth/login', array('as'=>'admin.auth.login.post','uses'=>'AuthController@postLogin')); });
    – liemphan Feb 22 '16 at 10:41
  • It's not working. It's still nothing happen, i don't know why :( – liemphan Feb 22 '16 at 13:14
  • I create middware in App\Modules\Admin\Http\Middleware because i use a module package. Do you think it is the cause of the error? – liemphan Feb 22 '16 at 13:22
  • 2
    Thanks Pananoid so much, I've solved this issue, The problem is the position which I put auth middleware before web middleware so it dont work. Now when I put web middleware before auth middleware, it work perfectly. Thanks pananoid again. – liemphan Feb 22 '16 at 14:00
  • Thanks @liemphan your last comment solved my problem here – Ramon Carvalho Jan 30 '19 at 14:39