Laravel - How to redirect to login if user is not authenticated

后端 未结 4 1847
悲&欢浪女
悲&欢浪女 2021-02-13 19:26

I\'m trying to use the __constructor from the extended class (AdminController extends AdminBaseController) but aparently it\'s not working

4条回答
  •  轮回少年
    2021-02-13 20:07

    Use middleware for this purpose and then in controller constructor use it as in example below.

    public function __construct()
    {
        $this->middleware('guest', ['except' => 'logout']);
    }
    

    And then you need to secure routes where you want from user to be logged in to access.

    Route::group(['middleware' => 'auth'], function() {
          Route::get('/dashboard', 'DashboardController@index');
    });
    

提交回复
热议问题