Table custom query, where from request path.

I have a table with sub-entities. I wan't to display only limited list of sub-entities based on param from request path: http://localhost:3005/admin/events/43
->query(Member::query()
->where('event_id', request()->route()->parameter('record'))
)
->query(Member::query()
->where('event_id', request()->route()->parameter('record'))
)
This renders well, however the form contains one action. When I click on this action:
->actions([
Tables\Actions\Action::make('accept')
->translateLabel()
->action(static fn(Member $record) => $record->approve())
->modalSubmitActionLabel(__('Accept'))
->modalHeading(__('Accept Member'))
->modalContent(fn(Member $record): View => view(
'livewire.show-member',
[
'event' => $record->event,
'record' => $record,
],
))
->hidden(static fn(Member $record) => $record->is_approved),
])
->actions([
Tables\Actions\Action::make('accept')
->translateLabel()
->action(static fn(Member $record) => $record->approve())
->modalSubmitActionLabel(__('Accept'))
->modalHeading(__('Accept Member'))
->modalContent(fn(Member $record): View => view(
'livewire.show-member',
[
'event' => $record->event,
'record' => $record,
],
))
->hidden(static fn(Member $record) => $record->is_approved),
])
The form for some reason is reloading with the request path of POST/PUT action, which doesn't have my argument. The question is: why does it reload the form? Is it the expected behavior of the framework?
Solution:
Thank you, it works! For the history: ```php public int $eventId; public function mount(): void...
Jump to solution
2 Replies
Dan Harrin
Dan Harrin7mo ago
yes, when livewire rerenders the page it will fetch that data again, its expected refactor your code to save the query parameter in a public property in mount() of the livewire component, then call that
Solution
Zhartaunik
Zhartaunik7mo ago
Thank you, it works! For the history:
public int $eventId;

public function mount(): void
{
$this->eventId = (int) request()->route()->parameter('record');
}

public function table(Table $table): Table
{
return $table
->query(Member::query()
->where('event_id', $this->eventId)
)
//...
public int $eventId;

public function mount(): void
{
$this->eventId = (int) request()->route()->parameter('record');
}

public function table(Table $table): Table
{
return $table
->query(Member::query()
->where('event_id', $this->eventId)
)
//...
Want results from more Discord servers?
Add your server