Relation Manager in Tab component of parent Resource
What I am trying to do: I want my "Accounts" resource to have tabbed Relation Managers for its Many-to-Many relationships. The reason I want the Relation Manager inside a Tab component on the parent resource is because I need the editable "name" form field to be displayed outside of the tabs, on top, so it's always visible.
What I did: I have tried declaring
in the EditAccount.php of the Resource pages
My issue/the error: the above solution puts the entire content of my EditForm in its own tab, which is different from my requirement.
Do I need to code a custom view/component or use some Livewire workarounds? This is my first project in Laravel (but not my first in php) and I've been following the documentation
4 Replies
Not 100% sure I follow, but you ca use AWOCodes table repeater form field for having the relationships within forms...
Repeaters can handle HasMany (one-to-many) relationships, I need to handle BelongsToMany (many-to-many) relationships, the page for the plugin doesn't say it extends that kind of support, if it's the same as the form repeated that's still not my use case
Well, this was misleading... I went and read the actual page on the Repeaters and I could use them with many-to-many if I made a custom pivot model and changed my helper functions to HasMany/BelongsTo, but even then Repeaters are still iffy because my related entities do not have just a few fields, the relation manager is the best for UX.
I think for the time being I'll make the detail of the editform collapsible so the relation managers can be browsed while the main 'name' field at the top is still visible, but a way to display the relation manager tabs as Tab items in a Tabs component on the parent resource would be a better solution

public static function form(Form $form): Form
{
return $form
->columns(1)
->schema([
Tabs::make()
->tabs([
Tabs\Tab::make('Post Details')
->icon('heroicon-o-document-text')
->schema([
...
]),
Tabs\Tab::make('Categories')
->visibleOn('edit')
->icon('heroicon-o-tag')
->schema([
Livewire::make(CategoriesRelationManager::class, fn (Post $record, Pages\EditPost $livewire): array => [
'ownerRecord' => $record,
'pageClass' => $livewire::class,
]),
]),
Tabs\Tab::make('Comments')
->visibleOn('edit')
->icon('heroicon-o-chat-bubble-left')
->schema([
Livewire::make(CommentsRelationManager::class, fn (Post $record, Pages\EditPost $livewire): array => [
'ownerRecord' => $record,
'pageClass' => $livewire::class,
]),
]),
]),
]);
}