F
Filament13mo ago
Barış

Row Action Issue: Incorrect Record Selection

Hello everyone, I hope you can assist me with a behavior issue I'm encountering when using a row action. What I am trying to do: I want to retrieve the current record when I click the button. What I did: I created a simple row action. My issue/the error: When I click the buttons, it fetches a different record instead of the selected one. Strangely, it seems to send the correct ID when posting, and the ID shown in the tooltip is as it should be. Code:
->actions([
Tables\Actions\Action::make('AssignToMe')
->label('Take ownership of this request')
->tooltip(function ($record) {
return 'customer id => ' . $record->id;
})
->button()
->outlined()
->color('success')
->icon('heroicon-s-user')
->action(function (Customer $customer) {
Notification::make()
->title("customer id => {$customer->id}")
->send();
}),
])
->actions([
Tables\Actions\Action::make('AssignToMe')
->label('Take ownership of this request')
->tooltip(function ($record) {
return 'customer id => ' . $record->id;
})
->button()
->outlined()
->color('success')
->icon('heroicon-s-user')
->action(function (Customer $customer) {
Notification::make()
->title("customer id => {$customer->id}")
->send();
}),
])
No description
2 Replies
gon.exe
gon.exe13mo ago
Did you try using $record ?
->action(function ($record) {
Notification::make()
->title("customer id => {$record->id}")
->send();
}),
->action(function ($record) {
Notification::make()
->title("customer id => {$record->id}")
->send();
}),
Barış
BarışOP13mo ago
Hello again, I solved my problem and I want to share it in case others experience the same issue. It seems like the problem originates from the getTabs method.
public function getTabs(): array
{
return [
'pending' => Tab::make('Bekleyen Talepler')
->icon('heroicon-o-clock')
->modifyQueryUsing(fn(Builder $query) => $query->where('status', 'pending')->orWhere('status', 'in_progress')),
'in_progress' => Tab::make('Üzerimdeki Talepler')
->icon('heroicon-o-phone-arrow-up-right')
->modifyQueryUsing(fn(Builder $query) => $query->where('status', 'in_progress')->where('user_id', auth()->id())),
'completed' => Tab::make('Tamamlananlar')
->icon('heroicon-o-check')
->modifyQueryUsing(fn(Builder $query) => $query->where('status', 'completed')),
];
}
public function getTabs(): array
{
return [
'pending' => Tab::make('Bekleyen Talepler')
->icon('heroicon-o-clock')
->modifyQueryUsing(fn(Builder $query) => $query->where('status', 'pending')->orWhere('status', 'in_progress')),
'in_progress' => Tab::make('Üzerimdeki Talepler')
->icon('heroicon-o-phone-arrow-up-right')
->modifyQueryUsing(fn(Builder $query) => $query->where('status', 'in_progress')->where('user_id', auth()->id())),
'completed' => Tab::make('Tamamlananlar')
->icon('heroicon-o-check')
->modifyQueryUsing(fn(Builder $query) => $query->where('status', 'completed')),
];
}
When I changed it to:
public function getTabs(): array
{
$userId = auth()->id();

return [
'pending' => $this->createTab('Bekleyen Talepler', 'heroicon-o-clock', fn(Builder $query) => $query->whereIn('status', ['pending', 'in_progress'])),
'in_progress' => $this->createTab('Üzerimdeki Talepler', 'heroicon-o-phone-arrow-up-right', fn(Builder $query) => $query->where('status', 'in_progress')->where('user_id', $userId)),
'completed' => $this->createTab('Tamamlananlar', 'heroicon-o-check', fn(Builder $query) => $query->where('status', 'completed')),
];
}

private function createTab(string $name, string $icon, callable $queryModifier): Tab
{
return Tab::make($name)
->icon($icon)
->modifyQueryUsing($queryModifier);
}
public function getTabs(): array
{
$userId = auth()->id();

return [
'pending' => $this->createTab('Bekleyen Talepler', 'heroicon-o-clock', fn(Builder $query) => $query->whereIn('status', ['pending', 'in_progress'])),
'in_progress' => $this->createTab('Üzerimdeki Talepler', 'heroicon-o-phone-arrow-up-right', fn(Builder $query) => $query->where('status', 'in_progress')->where('user_id', $userId)),
'completed' => $this->createTab('Tamamlananlar', 'heroicon-o-check', fn(Builder $query) => $query->where('status', 'completed')),
];
}

private function createTab(string $name, string $icon, callable $queryModifier): Tab
{
return Tab::make($name)
->icon($icon)
->modifyQueryUsing($queryModifier);
}
my problem was solved. It’s very interesting, but it seems to have solved my problem. Yes. I've tried everything imaginable.
Want results from more Discord servers?
Add your server