Relation manager in custom page

I have a custom page and I need to use the relation manager table in it.
class EditAmenities extends Page implements Forms\Contracts\HasForms
{
use Forms\Concerns\InteractsWithForms;

protected static string $resource = ListingResource::class;

protected static string $view = 'filament.resources.listing-resource.pages.edit-listing.edit-amenities';

protected function getActions(): array
{
return [];
}

protected function getTitle(): string
{
return '';
}
public $amenities;
public $listing;
public Listing $record;

public function mount(): void
{
$listing = $this->listing = Listing::findOrFail($this->record->id);
$this->form->fill([
'amenities' => $listing->amenities
]);
}

public function getFormModel(): Listing
{
return $this->listing;
}

public function update()
{
$this->listing->update($this->form->getState());

Notification::make()
->title('Saved successfully')
->success()
->send();
}
class EditAmenities extends Page implements Forms\Contracts\HasForms
{
use Forms\Concerns\InteractsWithForms;

protected static string $resource = ListingResource::class;

protected static string $view = 'filament.resources.listing-resource.pages.edit-listing.edit-amenities';

protected function getActions(): array
{
return [];
}

protected function getTitle(): string
{
return '';
}
public $amenities;
public $listing;
public Listing $record;

public function mount(): void
{
$listing = $this->listing = Listing::findOrFail($this->record->id);
$this->form->fill([
'amenities' => $listing->amenities
]);
}

public function getFormModel(): Listing
{
return $this->listing;
}

public function update()
{
$this->listing->update($this->form->getState());

Notification::make()
->title('Saved successfully')
->success()
->send();
}
This is the page. How can I add that relation manager table?
3 Replies
Cybrarist
Cybrarist2y ago
shouldn't you do it through getFormSchema method ?
Dennis Koch
Dennis Koch2y ago
You can either just embed a table (see the table builder docs) or have a look at the edit-records.blade.php on how relation managers are loaded with the default pages.
matthewpeavoy
matthewpeavoy14mo ago
I was able to add a relationship manager to a custom page using the following blade setup. I just created a new relation manager class (just a random PHP class, not in a resource) by copying / pasting the format. <x-filament-panels::page> <x-filament-panels::form wire:submit="update"> {{ $this->form }} {{-- // add form actions --}} <x-filament-panels::form.actions :actions="$this->getFormActions()" /> </x-filament-panels::form> @php $relationManagers = $this->getRelationManagers(); // dd($relationManagers); @endphp <x-filament-panels::resources.relation-managers :active-locale="null" :active-manager="0" :content-tab-label="'Tab'" :managers="$relationManagers" :owner-record="$record" :page-class="static::class" > </x-filament-panels::resources.relation-managers> </x-filament-panels::page> $record is just a model assigned in the mount() method, and this is how I'm pulling in the relation manager class. public function getRelationManagers(): array { return [ LicenseRelationManager::class ]; } One last note: :active-manager="0" is just an array key, so could be controlled dynamically. I haven't tried it with multiple managers yet.

Did you find this page helpful?