src/app/console/commands/HCPermissions.php
private function createRolesPermissions(array $aclData)
    {
        $allRolesActions = $this->extractAllActions($aclData);

        $uncheckedActionsOutput = [];

        foreach ( $this->rolesList as $roleRecord ) {
            // load current role permissions
            $roleRecord->load('permissions');

            // get current role permissions
            $currentRolePermissions = $roleRecord->permissions->pluck('action')->toArray();

            // if role already has permissions
            if( count($currentRolePermissions) ) {
                // unchecked actions
                $uncheckedActions = array_diff($allRolesActions[$roleRecord->slug], $currentRolePermissions);

                if( ! empty($uncheckedActions) ) {
                    $uncheckedActionsOutput[] = [$roleRecord->name, implode("\n", $uncheckedActions)];
                }
                
                continue;
            }


            // if role doesn't have any permissions than create it

            // get all permissions
            $permissions = Permissions::whereIn('action', $allRolesActions[$roleRecord->slug])->get();

            // sync permissions
            $roleRecord->permissions()->sync($permissions->pluck('id'));
        }

        // if role has unchecked actions than show which actions is unchecked
        if( $uncheckedActionsOutput ) {
            $this->table(['Role', 'Unchecked actions'], $uncheckedActionsOutput);
        }
    }
private function createRolesPermissions(array $aclData)
    {
        $allRolesActions = $this->extractAllActions($aclData);

        $uncheckedActionsOutput = [];

        foreach ( $this->rolesList as $roleRecord ) {
            // load current role permissions
            $roleRecord->load('permissions');

            // get current role permissions
            $currentRolePermissions = $roleRecord->permissions->pluck('action')->toArray();

            // if role already has permissions
            if( count($currentRolePermissions) ) {
                // unchecked actions
                $uncheckedActions = array_diff($allRolesActions[$roleRecord->slug], $currentRolePermissions);

                if( ! empty($uncheckedActions) ) {
                    $uncheckedActionsOutput[] = [$roleRecord->name, implode("\n", $uncheckedActions)];
                }
                
                continue;
            }


            // if role doesn't have any permissions than create it

            // get all permissions
            $permissions = Permissions::whereIn('action', $allRolesActions[$roleRecord->slug])->get();

            // sync permissions
            $roleRecord->permissions()->sync($permissions->pluck('id'));
        }

        // if role has unchecked actions than show which actions is unchecked
        if( $uncheckedActionsOutput ) {
            $this->table(['Role', 'Unchecked actions'], $uncheckedActionsOutput);
        }
    }
private function createRolesPermissions ( array $ aclData ) { $ allRolesActions = $ this -> extractAllActions ( $ aclData ) ; $ uncheckedActionsOutput = [ ] ; foreach ( $ this -> rolesList as $ roleRecord ) { // load current role permissions $ roleRecord -> load ( 'permissions' ) ; // get current role permissions $ currentRolePermissions = $ roleRecord -> permissions -> pluck ( 'action' ) -> toArray ( ) ; // if role already has permissions if ( count ( $ currentRolePermissions ) ) { // unchecked actions $ uncheckedActions = array_diff ( $ allRolesActions [ $ roleRecord -> slug ] , $ currentRolePermissions ) ; if ( ! empty ( $ uncheckedActions ) ) { $ uncheckedActionsOutput [ ] = [ $ roleRecord -> name , implode ( "\n" , $ uncheckedActions ) ] ; } continue ; } // if role doesn't have any permissions than create it // get all permissions $ permissions = Permissions :: whereIn ( 'action' , $ allRolesActions [ $ roleRecord -> slug ] ) -> get ( ) ; // sync permissions $ roleRecord -> permissions ( ) -> sync ( $ permissions -> pluck ( 'id' ) ) ; } // if role has unchecked actions than show which actions is unchecked if ( $ uncheckedActionsOutput ) { $ this -> table ( [ 'Role' , 'Unchecked actions' ] , $ uncheckedActionsOutput ) ; } }
Creating roles permissions

@param $aclData
@internal param $acl
Creating roles permissions