php - Laravel 5.0 redirect not working -
i developing custom access control system in laravel 5.0. have created helper function check if user has permission before executing function
public function index() { if( has_permission( 'blahblah' ) ) { // actions } }
and have helper function has_permission
function has_permission( $action ) { $current_user_perms = array( 'view_users', 'create_users', 'edit_users', 'delete_users' ); if( !in_array( $action, $current_user_perms ) ) { return redirect()->route('access_denied'); } return true; }
but when permission fails, not redirecting. idea?
you should return redirect response make working.
- change helper return boolean value:
function has_permission($action) { $current_user_perms = ['view_users', 'create_users', 'edit_users']; return in_array($action, $current_user_perms); }
- in controller check helper method , return redirect response if needed:
public function index() { if(!has_permission('blahblah')) { return redirect()->route('access_denied'); } // stuff }
ps. highly recomend read middlewares , use them instead of helpers, that's right laravel-way achieve simple permissions functionality.
Comments
Post a Comment