Auth::user() returns null

后端 未结 6 1494
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-03 04:47

I use Laravel 5.2 and have a problem with middleware. There is the code in the routes.php


    use Illuminate\\Contracts\\Auth\\Access\\Gate;


    Route::group([         


        
6条回答
  •  借酒劲吻你
    2020-12-03 05:05

    Any route that uses Auth() must be encapsulated in the web middleware. You're close, just move your Route::group(['prefix' => 'admin'], ...) into the group above.

    Route::group(['middleware' => 'web'], function () {
    
        Route::auth();
    
        Route::get('/', 'HomeController@index');
    
        // Moving here will ensure that sessions, csrf, etc. is included in all these routes
        Route::group(['prefix'=>'admin',  'middleware' => 'admin'], function(){
            Route::get('/', function(){
                return view('admin.index');
            });
    
            Route::get('/user', function(){
                return view('admin.user');
            });
        });
    });
    

提交回复
热议问题