Matt
Matt

Reputation: 1131

Cartalyst Sentinel get all roles

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!

Upvotes: 1

Views: 2895

Answers (3)

Nabil Kadimi
Nabil Kadimi

Reputation: 10394

To get all available roles as array:

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

Or, if you need Eloquent(Role) objects:

$roles = DB::table('roles')->get();

Upvotes: 1

Zugor
Zugor

Reputation: 881

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/>";
    }

Upvotes: 0

Matt
Matt

Reputation: 1131

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

Upvotes: 0

Related Questions