php - Laravel 4: pass value from filter to controller -
is there anyway pass variable value filter controller,
i tried homecoming value break controller execution:
route::filter('is_admin', function() { $data = db::select( 'select level users user_id = ? limit 1', array(auth::user()->id) ); if($data[0]->level > 5) { homecoming 'not authorized'; } //return level here });
you should alter filter into:
route::filter('admin', function() { if (auth::guest() || auth::user()->level > 5) { homecoming 'not authorized'; } });
and in paths protected filter can use:
echo auth::user()->name;
or
$user = auth::user(); echo $user->name; echo $user->level;
so don't need pass info filter controllers or views. can utilize in controllers, can utilize in other models, can utilize in view.
php laravel laravel-4
No comments:
Post a Comment