Level 104
If you return in the foreach loop, then the function returns.
You can get an array of the user's role names using:
auth()->user()->roles()->pluck('name')->all();
I don't believe that you need a separate getRoles function for this?
Next, "rendering an array" is something entirely different... how do you want them rendered as a comma-separated list
{{ auth()->user()->roles()->pluck('name')->implode(', ') }}
or as an unordered list:
<ul>
@foreach(auth()->user()->roles as $role)
<li>{{ $role->name }}</li>
@endforeach
</ul>
Or something else???
1 like