Table actions returning the wrong records

I'm making a table for users to see the messages they're allowed to check. It only has a view action. The project uses livewire components instead of filament panels. I already have multiple tables with custom queries, but this one is the first to cause this issue. The query is getting the records respecting the conditions as it should. So at first glance, the table seems fine, but no matter which action I try (view, edit, delete) of any record, the action always gets the same record. If I remove the query conditions to recover all the records or only keep one condition, the actions recover the right records. Depending on which conditions I keep, there are some cases where the first two of the table will be fine, but the rest will get one of the first two. The issue is before getting the infolist, I'm having the same reaction if I dd the record instead of the infolist or a form. Has anyone encountered something similar?
6 Replies
Ibakha
IbakhaOP2w ago
public function table(Table $table): Table
{
return $table
->query(Message::query()
->where(function ($query) {
$query->where('role', null)
->where('department_id', null)
->where('date', '<=', today());
})
->orWhere(function ($query) {
$query->where('role', null)
->whereIn('department_id', Auth::user()->departments->pluck('id'))
->where('date', '<=', today());
})
->orWhere(function ($query) {
$query->whereIn('role', Auth::user()->roles->pluck('tag'))
->where('department_id', null)
->where('date', '<=', today());
})
->orWhere(function ($query) {
$query->whereIn('role', Auth::user()->roles->pluck('tag'))
->whereIn('department_id', Auth::user()->departments->pluck('id'))
->where('date', '<=', today());
})
)
->deferLoading()
->defaultSort('updated_at', 'desc')
->defaultPaginationPageOption(10)
->paginated([10])
->columns([
Split::make([
TextColumn::make('date')
->label(__('common.date'))
->date()
->color('gray')
->grow(false),
TextColumn::make('title')
->label(__('common.title'))
->searchable()
->weight(FontWeight::Bold)
->limit(50),
])
])
->actions([
ViewAction::make()
->modalHeading(fn (Message $record) => ($record->title))
->infolist(Message::getInfolist())
->slideOver(),
]);
}
public function table(Table $table): Table
{
return $table
->query(Message::query()
->where(function ($query) {
$query->where('role', null)
->where('department_id', null)
->where('date', '<=', today());
})
->orWhere(function ($query) {
$query->where('role', null)
->whereIn('department_id', Auth::user()->departments->pluck('id'))
->where('date', '<=', today());
})
->orWhere(function ($query) {
$query->whereIn('role', Auth::user()->roles->pluck('tag'))
->where('department_id', null)
->where('date', '<=', today());
})
->orWhere(function ($query) {
$query->whereIn('role', Auth::user()->roles->pluck('tag'))
->whereIn('department_id', Auth::user()->departments->pluck('id'))
->where('date', '<=', today());
})
)
->deferLoading()
->defaultSort('updated_at', 'desc')
->defaultPaginationPageOption(10)
->paginated([10])
->columns([
Split::make([
TextColumn::make('date')
->label(__('common.date'))
->date()
->color('gray')
->grow(false),
TextColumn::make('title')
->label(__('common.title'))
->searchable()
->weight(FontWeight::Bold)
->limit(50),
])
])
->actions([
ViewAction::make()
->modalHeading(fn (Message $record) => ($record->title))
->infolist(Message::getInfolist())
->slideOver(),
]);
}
LeandroFerreira
probably an issue with your query. Try inspecting the view button in devtools and verify the id parameter in the mountTableAction
Ibakha
IbakhaOP7d ago
all buttons have their record respective id in mountTableAction but still fetch the same record here's the buttons, the id at the end is matching the record for each button. When clicked, it's always returning the same record in the table, example the record with id of two even if the mountTableAction as an other id in parameter
<button class="fi-link group/link relative inline-flex items-center justify-center outline-none fi-size-sm fi-link-size-sm gap-1 fi-color-gray fi-ac-action fi-ac-link-action" type="button" wire:loading.attr="disabled" wire:click="mountTableAction('view', '14')">
<button class="fi-link group/link relative inline-flex items-center justify-center outline-none fi-size-sm fi-link-size-sm gap-1 fi-color-gray fi-ac-action fi-ac-link-action" type="button" wire:loading.attr="disabled" wire:click="mountTableAction('view', '14')">
Caste!
Caste!7d ago
Hello I have the same issues and it was for modifying the query in the table, I resolve it using a scope into the model
Ibakha
IbakhaOP7d ago
Thanks! I'm not sure why it's not working in the table, but the scope is working! 😄
Caste!
Caste!7d ago
no problem!

Did you find this page helpful?