Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 2 years ago.
0
$users = User::with('roles')->all();
0

Thanks the full solution I ended up with was this.

User::with('roles')->get();

Then pass that to the view with

return view('admin.users.index')->with('users', $users);

And loop through the results like so:

@foreach ($users as $user)
	<tr>
		<td>{!! $user->id !!}</td>
		<td>{!! $user->name !!}</td>
		<td>{!! $user->email !!}</td>
		<td>{!! $user->created_at !!}</td>
		<td>{!! $user->updated_at !!}</td>
		<td>
		
			@foreach ($user->roles as $role)
			{!! $role->name !!}<br />
			@endforeach
		
		</td>
	</tr>
	@endforeach
0

Sign in to participate in this thread!

Eventy

Your banner here too?

SCC-Lee scc-lee Joined 22 Oct 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.