Laravel-admin: How to get user list by role ?

Created on 5 May 2018  ·  1Comment  ·  Source: z-song/laravel-admin

  • Laravel Version: 5.5.34
  • PHP Version:7.2
  • Laravel-admin: 1.5.9
  1. administrator
  2. editor
  3. member
if (Admin::user()->isRole('editor')) {
     //want to query only editor users and members.
}

How can I do ?

Thanks

Most helpful comment

Try this:

use Encore\Admin\Auth\Database\Administrator;

$users = Administrator::whereHas('roles',  function ($query) {
    $query->whereIn('name', ['editor', 'members']);
})->get();

>All comments

Try this:

use Encore\Admin\Auth\Database\Administrator;

$users = Administrator::whereHas('roles',  function ($query) {
    $query->whereIn('name', ['editor', 'members']);
})->get();
Was this page helpful?
0 / 5 - 0 ratings

Related issues

cdhraesaemer picture cdhraesaemer  ·  3Comments

fokoz picture fokoz  ·  3Comments

benny-sun picture benny-sun  ·  3Comments

donglianyou picture donglianyou  ·  3Comments

zhenyangze picture zhenyangze  ·  3Comments