Get active relation manager table filters from custom page

Is there any straightforward way to access the instance of the active relation manager from my custom page? I'm trying to make the custom page to respond to certain relation manager "events" like when a filter is applied, or the active relation manager changes. Is this the right approach? Or perhaps i should invert the logic, and fire events from the relation managers itselves. Any insight will be greatly appreciated!
Solution:
For anyone having the same questions, i'll post what i ended up doing. What i wanted was to get the relation manager table filters from my custom page which they were shown. My solution was the following: I'm using
AnourValar\EloquentSerialize
AnourValar\EloquentSerialize
library to serialize the query builder and save it to the application cache. So in the Relation Manager table, i do the following: ```...
Jump to solution
2 Replies
CORONEL
CORONELOP6mo ago
PS: I'm adding the relation managers to the custom page like this:
@php
$relationManagers = $this->getRelationManagers();
@endphp


@if (count($relationManagers))
<x-filament-panels::resources.relation-managers :active-locale="isset($activeLocale) ? $activeLocale : null"
:active-manager="$this->activeRelationManager ?? array_key_first($relationManagers)" :content-tab-label="$this->getContentTabLabel()"
:content-tab-contained="true" :managers="$relationManagers" :owner-record="$record" :page-class="static::class">
</x-filament-panels::resources.relation-managers>
@endif
@php
$relationManagers = $this->getRelationManagers();
@endphp


@if (count($relationManagers))
<x-filament-panels::resources.relation-managers :active-locale="isset($activeLocale) ? $activeLocale : null"
:active-manager="$this->activeRelationManager ?? array_key_first($relationManagers)" :content-tab-label="$this->getContentTabLabel()"
:content-tab-contained="true" :managers="$relationManagers" :owner-record="$record" :page-class="static::class">
</x-filament-panels::resources.relation-managers>
@endif
And setting them using the custom page
public static function getRelations(): array{...}
public static function getRelations(): array{...}
method.
Solution
CORONEL
CORONEL6mo ago
For anyone having the same questions, i'll post what i ended up doing. What i wanted was to get the relation manager table filters from my custom page which they were shown. My solution was the following: I'm using
AnourValar\EloquentSerialize
AnourValar\EloquentSerialize
library to serialize the query builder and save it to the application cache. So in the Relation Manager table, i do the following:
$table...->filtersApplyAction(function ($livewire) {
$serialized = EloquentSerializeFacade::serialize($livewire->getFilteredTableQuery());
Cache::put(get_class($livewire), $serialized);
$livewire->dispatch('refreshPage');
})
$table...->filtersApplyAction(function ($livewire) {
$serialized = EloquentSerializeFacade::serialize($livewire->getFilteredTableQuery());
Cache::put(get_class($livewire), $serialized);
$livewire->dispatch('refreshPage');
})
And in my custom page, i have the following:
protected $listeners = ['refreshPage' => '$refresh'];

public function myMethodWhereINeedTheFilters(){
$activeRelationManager = $this->getRelationManagers()[$this->activeRelationManager];
$filtered = null;
try {
$filtered = EloquentSerializeFacade::unserialize(Cache::get($activeRelationManager));
} catch (Exception $e) {
}
// dd($filtered);

if ($filtered) {
$pointsQuery = $filtered;
} else {
$pointsQuery = $this->record->points();
}

$data = $pointsQuery->get();
}
protected $listeners = ['refreshPage' => '$refresh'];

public function myMethodWhereINeedTheFilters(){
$activeRelationManager = $this->getRelationManagers()[$this->activeRelationManager];
$filtered = null;
try {
$filtered = EloquentSerializeFacade::unserialize(Cache::get($activeRelationManager));
} catch (Exception $e) {
}
// dd($filtered);

if ($filtered) {
$pointsQuery = $filtered;
} else {
$pointsQuery = $this->record->points();
}

$data = $pointsQuery->get();
}
Want results from more Discord servers?
Add your server