0

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 :( Thanks for help.

apokryfos
  • 38,771
  • 9
  • 70
  • 114
Tomek Greber
  • 5
  • 1
  • 7

2 Answers2

0

what about this:

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

I think this is what you want.

Levente Otta
  • 713
  • 6
  • 17