php - Laravel 4 Route Level Access -
i need add level access website , code route :
route::get('/', array( 'as' => 'home-view', 'uses' => 'homecontroller@viewhome' )); /* authenticated group */ route::group(array('before' => 'auth'), function(){ route::get('/', array( 'as' => 'admin-view', 'uses' => 'admincontroller@viewadmin' )); } /* unauthenticated group */ route::group(array('before' => 'guest'), function(){ route::get('/signin', array( 'as' => 'user-signin-get', 'uses' => 'usercontroller@getsignin' )); }
i need add level access "user" or "admin". how can filter route? simple possiple or recommend?
you can have many filters single route like. consider this:
route::group(array('before' => 'auth|hasadminlevel'), function(){ route::get('/', array( 'as' => 'admin-view', 'uses' => 'admincontroller@viewadmin' )); });
this apply both auth
hasadminlevel
filter admin-view
route. hasadminlevel
route custom filter need define.
update
hasadminlevel
custom filter, , can defined this:
route::filter('hasadminlevel', function() { if(auth::user()->level != 'admin') { return redirect::to('/'); } });
where place little you, place in aptly named app/filters.php
.
Comments
Post a Comment