Skip to content

How to get users by group? #638

Answered by datamweb
code353535 asked this question in Q&A
Feb 15, 2023 · 1 comments · 2 replies
Discussion options

You must be logged in to vote

Hello, welcome to Shield.
This issue is not directly related to the Shield. You must master the CI4 framework.

What I understand is that you want to list users who are in group superadmin.
For this, you can add the following function to your custom UserModel:

public function getUsersByGroup($groupName = 'users', $returnFields= 'username'){
  $getUsersByGroup = $this->db->table('auth_groups_users')
    ->select($returnFields)
    ->join('users', 'users.id = auth_groups_users.user_id')
    ->getWhere(['group' => $groupName])
    ->getResult();
   
return($getUsersByGroup);
}

Then use it as follows:

$userModel = model(UserModel::class);
dd($userModel->getUsersByGroup($groupName = 'superadmin', 

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@code353535
Comment options

@datamweb
Comment options

Answer selected by code353535
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants