php - Protecting all admin/ routes with auth in Laravel -


i brand new laravel , setting admin panel authorization on first application. way have files setup setup is:

controllers/     admin/         dashboard.php         settings.php     non-admin-controller1.php     non-admin-controller1.php views/     admin/         dashboard.blade.php         login.blade.php         template.blade.php     non-admin-view1.php     non-admin-view1.php     non-admin-view1.php 

...and these routes

route::get('admin/login', function() {     return view::make('admin.login'); });  route::get('admin/logout', function() {     return auth::logout();     return redirect::to('admin/login'); });  route::post('admin/login', function() {     $userdata = array('username' => input::get('username'),                       'password' => input::get('password'));      if (auth::attempt($userdata))     {         return redirect::to('admin');     }     else     {         return redirect::to('admin/login')->with('login_errors',true);     } });  route::controller('admin.dashboard');  route::get('admin', array('before' => 'auth', function() {     return redirect::to_action('admin@dashboard'); }));  route::filter('auth', function() {     if (auth::guest()) return redirect::to('admin/login'); }); 

when go /admin redirected admin/login , asked login how need work. upon logging in redirected admin/dashboard , looks there too. having 2 problems however.

  1. when go admin/logout logged out greeted blank page (it's not redirecting admin/login)

  2. when logged out, if go admin/dashboard greeted error

error rendering view: [admin.dashboard]

trying property of non-object

what doing wrong here? doing right? make more sense create separate bundle admin? thanks!

so able solve problem different way. created (base) admin_controller in root of controllers folder, constructor calling auth filter before execution:

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

and made admin related controllers in /controllers/admin extend admin_controller , call 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 eloquent solution, job!


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -