Mount array with user permissions

1

I need to mount an array in PHP (LARAVEL) and I can not find a way to do it.

I have a user system with roles and permissions. When I view the user, I clear all the permissions, but one below the other. Ex:

>     users-index
>     users-show
>     users-create
>     roles-create
>     roles-delete

But I would like to do the following:

Get all these permissions and separate them by category to list in separate tables, where this is the category is the word before the "-" (USERS-index), ex array:

  

ArrayAll = [                users = [                               users-index,                               users-show,                               users-create                              ]                 roles = [                               roles-create,                               roles-delete                             ]                             ]

I count on ideas! Hugs

    
asked by anonymous 20.05.2016 / 03:47

1 answer

2

If I understand correctly, I think it helps you.

$teuArrayDePermissoes = array('users-index','users-show','users-create','roles-create','roles-delete');
$newArray = array();
foreach($teuArrayDePermissoes as $permissao){
    $parts = explode("-", $permissao);
    $newArray[$parts[0]][] = $permissao;
}
var_dump($newArray);

It should display in the output the array that you want

    
27.05.2016 / 22:00