I came across this:
$users = User::role('Super Admin')->get();
but don't know how to select id,name
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
In my Laravel-5.8 Spatie Project. I want to query the id and name of user in users table where Spatie User Role is "Super Admin".
How do I do this?
Thank you.
From the docs
$users = User::role('writer')->get(); // Returns only users with the role 'writer'
so, provided the name of the role is EXACTLY 'Super Admin' then
$users = User::role('Super Admin')->get();
$users->first()->name;
$users->first()->id;
or
$users = User::role('Super Admin')->pluck('name','id');
or
@foreach($users as $user)
<option value="{{ $user->id }}" >{{ $user->name }}</option>
@endforeach
Just depends how you want to use these users
Please or to participate in this conversation.