public function assignRoles($groups, $bypassPermissionCheck = false)
    {
        // allow permission bypass only in the local environment
        if(config('app.env') == 'production' && $bypassPermissionCheck) {
            $bypassPermissionCheck = false;
        }

        // check if a user has permissions to access this link
        if(!$bypassPermissionCheck) {
            if (!self::hasAccess('user', 'update') && !self::hasAccess('user', 'create')) {
                return false;
            }
        }

        // First delete all previous relations
        RoleRelation::where('userID', $this->userID)->delete();

        $roles = [];

        // in case int is given
        if(is_numeric($groups)) {
            $groups = [$groups];
        }

        foreach ($groups as $groupID){
            $roles[] = [
              'userID' => $this->userID,
              'groupID' => (isset($groupID['groupID']) ? $groupID['groupID'] : $groupID)
            ];
        }

        if(RoleRelation::insert($roles)) {
            return true;
        }
        return false;
    }
public function assignRoles($groups, $bypassPermissionCheck = false)
    {
        // allow permission bypass only in the local environment
        if(config('app.env') == 'production' && $bypassPermissionCheck) {
            $bypassPermissionCheck = false;
        }

        // check if a user has permissions to access this link
        if(!$bypassPermissionCheck) {
            if (!self::hasAccess('user', 'update') && !self::hasAccess('user', 'create')) {
                return false;
            }
        }

        // First delete all previous relations
        RoleRelation::where('userID', $this->userID)->delete();

        $roles = [];

        // in case int is given
        if(is_numeric($groups)) {
            $groups = [$groups];
        }

        foreach ($groups as $groupID){
            $roles[] = [
              'userID' => $this->userID,
              'groupID' => (isset($groupID['groupID']) ? $groupID['groupID'] : $groupID)
            ];
        }

        if(RoleRelation::insert($roles)) {
            return true;
        }
        return false;
    }
public function assignRoles ( $ groups , $ bypassPermissionCheck = false ) { // allow permission bypass only in the local environment if ( config ( 'app.env' ) == 'production' && $ bypassPermissionCheck ) { $ bypassPermissionCheck = false ; } // check if a user has permissions to access this link if ( ! $ bypassPermissionCheck ) { if ( ! self :: hasAccess ( 'user' , 'update' ) && ! self :: hasAccess ( 'user' , 'create' ) ) { return false ; } } // First delete all previous relations RoleRelation :: where ( 'userID' , $ this -> userID ) -> delete ( ) ; $ roles = [ ] ; // in case int is given if ( is_numeric ( $ groups ) ) { $ groups = [ $ groups ] ; } foreach ( $ groups as $ groupID ) { $ roles [ ] = [ 'userID' => $ this -> userID , 'groupID' => ( isset ( $ groupID [ 'groupID' ] ) ? $ groupID [ 'groupID' ] : $ groupID ) ] ; } if ( RoleRelation :: insert ( $ roles ) ) { return true ; } return false ; }
Assign roles to a user.

@param  array|int                       $groups groups that are selected in frontend for the new or existing user
@param  boolean Bypass permission check. Useful when creating users via CLI.
@return bool
Assign roles to a user .