F
Filamentβ€’2mo ago
aldec

Combine Relationship Manager tabs and form tabs

Is it possible to combine the tab created from hasCombinedRelationManagerTabsWithContent() with the tabs from a form?
Solution:
much better: ```php Livewire::make(YourRelationManager::class, fn (Page $livewire, YourModel $record) => [ 'ownerRecord' => $record,...
Jump to solution
10 Replies
LeandroFerreira
LeandroFerreiraβ€’2mo ago
you mean, inside the form, not this right?
aldec
aldecOPβ€’2mo ago
I can't access your link, sorry
No description
LeandroFerreira
LeandroFerreiraβ€’2mo ago
my bad, this
aldec
aldecOPβ€’2mo ago
Yes, I used this and now I have tabs for Edit and the Relations and below this tabs from the form. It would be nice to combine them into a single row.
No description
LeandroFerreira
LeandroFerreiraβ€’2mo ago
it could be better, but it should work: in the RelationManager class, add this:
public function mount(): void
{
$this->ownerRecord = YourModel::find(request()->route('record'));
$pageClass = str(request()->route()->getAction('controller'))->remove('@__invoke')->toString();
$this->pageClass = $pageClass;

parent::mount();
}
public function mount(): void
{
$this->ownerRecord = YourModel::find(request()->route('record'));
$pageClass = str(request()->route()->getAction('controller'))->remove('@__invoke')->toString();
$this->pageClass = $pageClass;

parent::mount();
}
In the Form tab:
use Filament\Forms\Components\Livewire;
...

Tabs\Tab::make('xx')
->schema([
Livewire::make(YourRelationManager::class)
])
use Filament\Forms\Components\Livewire;
...

Tabs\Tab::make('xx')
->schema([
Livewire::make(YourRelationManager::class)
])
aldec
aldecOPβ€’2mo ago
YourModel in the RelationManager refers to target model. For my use case right now this should work, but a more reusable solution would be nice. Thanks so far!
Solution
LeandroFerreira
LeandroFerreiraβ€’2mo ago
much better:
Livewire::make(YourRelationManager::class, fn (Page $livewire, YourModel $record) => [
'ownerRecord' => $record,
'pageClass' => $livewire::class,
]),
Livewire::make(YourRelationManager::class, fn (Page $livewire, YourModel $record) => [
'ownerRecord' => $record,
'pageClass' => $livewire::class,
]),
and remove the mount method
LeandroFerreira
LeandroFerreiraβ€’2mo ago
nice tip btw, I'll create a content about this πŸ˜…
aldec
aldecOPβ€’2mo ago
Awesome! Thank you very much! This has the additional benefit of not having a page reload like the hasCombinedRelationManagerTabsWithContent method has
aldec
aldecOPβ€’5w ago
Hey, I'm coming back to this, feeling stupid that I didn't notice it earlier: 1. It is still necessary to load the RelationManager in the resources getRelations method, otherwise I can't create new entries (symfony error not finding the component), but then I have it under each form visible again... bummer. 2. Having this Livewire component in my tabs seems to hijack the form submit process, because nothing happens if i try to edit a form where this Livewire
Want results from more Discord servers?
Add your server