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.

  1. 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); } 
  1. 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

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -