phplaravellaravel-bladelaravel-permissionpluck

Laravel and spatie/laravel-permission - plucking names of roles to a view


I want in Laravel to "pluck" to the view names of roles, each in different badge.

My code:

<td><span class="badge badge-secondary">{{ $user->roles()->pluck('name')->implode(' ') }}</span></td>

My result:

enter image description here

I am getting all role names in one span class.


Solution

  • what about this:

    <td>
        @foreach($user->roles()->pluck('name') as $role_name){
           <span class="badge badge-secondary">{{ $role_name }}</span>
        @endforeach
    </td>