authentication - Laravel 4 filter group routes for different roles -
i have 3 roles , admin panel , want change links (and routes) on panel according roles , dont use packages ... have 1 common filter , 1 admin filter , 1 moderator filter , 1 different user filter. different user filter want change links in control panel . problem :
route::group(array('before' => 'common'), function(){ route::controller('panel','admin_panelcontroller'); route::controller('phone','phnecontroller'); route::controller('internet','internetcontroller'); route::controller('message','messagecontroller'); // siteden gelen başvurular /* admin */ route::group(array('before' => 'admin'), function() { route::controller('useroptions','useroptionscontroller'); }); /* moderator */ route::group(array('before' => 'mod'), function() { route::controller('notifications','notificationscontroller'); }); }); /* different user */ route::group(array('before' => 'diffuser'), function() { route::controller('panel','admin_panelcontroller'); });
i want show panel diffuser , block other routes diffuser, when write these final codes different user , above of these part doesnt work !
please me , waiting help!
my filters
route::filter('common', function() { if (auth::guest() ) { return redirect::guest('login'); } }); route::filter('admin', function() { if (auth::guest() || auth::user()->type !== "admin" ) { return redirect::guest('login'); } }); route::filter('mod', function() { if (auth::guest() || auth::user()->type !== "mod" ) { return redirect::guest('login'); } }); route::filter('diffuser', function() { if (auth::guest() || auth::user()->type !== "diffuser" ) { return redirect::guest('login'); } });
filter checks 'diffuser' needs apply phone/internet/message, since needs prohibit viewing of routes. try this:
routes.php
route::group(array('before' => 'common'), function() { route::group(array('before' => 'set_links_diffuser'), function() route::controller('panel','admin_panelcontroller'); }); route::group(array('before' => 'prohibit_diffuser'), function() { route::controller('phone','phnecontroller'); // check spelling of phne route::controller('internet','internetcontroller'); route::controller('message','messagecontroller'); }); route::group(array('before' => 'allow_only_admin'), function() { route::controller('useroptions','useroptionscontroller'); }); route::group(array('before' => 'allow_only_mod'), function() { route::controller('notifications','notificationscontroller'); }); });
filters.php
route::filter('common', function() { if (auth::guest()){ return redirect::guest('login'); } }); // no need repeat auth::guest() check these filters, // since 'common' route::filter('allow_only_admin', function() { if (auth::user()->type !== "admin" ){ return redirect::guest('login'); } }); route::filter('allow_only_mod', function() { if (auth::user()->type !== "mod" ){ return redirect::guest('login'); } }); route::filter('prohibit_diffuser', function() { if (auth::user()->type == "diffuser" ){ return redirect::guest('login'); } }); route::filter('set_links_diffuser', function() { if (auth::user()->type == "diffuser" ){ // stuff here change links on control panel } });
Comments
Post a Comment