1

So I have chosen Sentinel as an ACL for my CMS. And I'm getting to the point where I need to assign roles to users. To do that I need to get a list of all available roles. But when requesting:

Role::all()

from my model (which extends the EloquentRole) I only get id's. While an id is a good start I'm going to need more. Preferably:

Role::pluck('id', 'slug', 'name')

I have searched high and low for a way to get this. But neither the documentation nor the world seem to utter a word on this.

Any tips would be greatly appreciated!

Matt
  • 1,081
  • 15
  • 27

3 Answers3

1

To get all available roles as array:

$roles = Sentinel::getRoleRepository()->all();

Or, if you need Eloquent(Role) objects:

$roles = DB::table('roles')->get();
Nabil Kadimi
  • 10,078
  • 2
  • 51
  • 58
0

So it seems I was in a bit of an eloquent flow. It seems

Role::all()
Role::pluck(...)

Indeed do not work. But a regular:

Role::get()

does. Whoopsie

Matt
  • 1,081
  • 15
  • 27
0

There's getRoles() function in

cartalyst/sentinel/src/Roles/RoleableInterface.php

You can use it with \Sentinel::getRoles() in Laravel.

This one might be more simple.

$roles = Sentinel::getRoleRepository()->get();
    foreach ($roles as $role) {
        echo $role->name."<br/>";
    }
Zugor
  • 870
  • 8
  • 17