Protecting all admin/ routes with auth in Laravel

前端 未结 3 1214

I am brand new to laravel and am setting up admin panel authorization on my first application. The way I have my files setup currently setup is:

controllers/
             


        
3条回答
  •  不思量自难忘°
    2021-02-06 01:34

    So I was able to solve my problem a slightly different way. I created an (base) Admin_Controller in the root of the controllers folder, with a constructor calling the auth filter before execution:

    class Admin_Controller extends Base_Controller {
    
        public function __construct()
        {
            $this->filter('before', 'auth');
        }
    
    }
    

    and then made all my admin related controllers in /controllers/admin extend Admin_Controller and call the parent constructor:

    class Admin_Dashboard_Controller extends Admin_Controller {
    
        public function __construct()
        {
            parent::__construct();
        }
    
        public function action_index()
        {
            return View::make('admin.dashboard');
        }
    
    }
    

    This might not be the most eloquent solution, but it does the job!

提交回复
热议问题