Relations can be nested, so this would work:
$users = User::with('roles.permissions')->get();
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Here is the index method on my UsersController
class UsersController extends Controller {
/**
* Returns all classmates
*
* @return \Illuminate\View\View
*/
public function index()
{
$users = User::with('roles')->get();
return view('users.index', compact('users'));
}
}
I would also like to get the Permissions associated with the Roles and pass them to the view too. I know this may not be the best way to do it but for the time being we just want to show that it works.
Relations can be nested, so this would work:
$users = User::with('roles.permissions')->get();
Please or to participate in this conversation.