Certainly! This is a common situation when working with Filament's RelationManagers.
Problem Recap:
When you use a relation manager (e.g. AccountsRelationManager from your Contract resource), Eloquent may not eager load the nested relations (in this case, roles of each account), which means $account->roles will be empty unless explicitly loaded.
Why?
In the main Accounts resource, Filament's table/form typically eager loads all columns/relations you use. But in a RelationManager, only the direct relation (accounts) is loaded—nested relations like roles are not eager-loaded by default.
Solution:
Override the getTableQuery() or getEloquentQuery() method in your AccountsRelationManager and eager-load the roles relation.
Example:
class AccountsRelationManager extends RelationManager
{
protected static string $relationship = 'accounts';
public static function getTableQuery(RelationManager $livewire)
{
return parent::getTableQuery($livewire)
->with('roles'); // Eager load roles
}
// If you are using a different Filament version or Table, try getEloquentQuery:
// public static function getEloquentQuery(): Builder
// {
// return parent::getEloquentQuery()->with('roles');
// }
}
Now, roles will be available when you access them in your view (e.g. roles.name in your component).
Note:
- Make sure you use
.with('roles'), not.with('roles.name'). - If you use
getTableQuery(), be sure it returns a query builder instance. If your version usesgetEloquentQuery(), override that instead.
Summary:
Yes, relations are accessible in a RelationManager as long as you eager load them in the respective query. Just add a .with('roles') to your query override.
Let me know if you need an example specifically for forms or InfoList instead of a Table!