Custom widget property being set after widget reload in action

I'm using the following custom action to navigate between between weeks of upcoming birthdays users. When the action runs, we increment the start date property. However, the property seems to lag a week behind the actual value. I believe this is happening due to the reload happening before the property is being set? How can I prevent this?
class BirthdayMembersWidget extends BaseWidget
{
public Carbon $startDate;

public function mount(): void
{
$this->startDate = today();
}

protected function getTableHeaderActions(): array
{
return [
Tables\Actions\Action::make('Next')
->label(new HtmlString('»'))
->action(function () {
$this->startDate = $this->startDate->addWeek();
}),
];
}

protected function getTableQuery(): Builder
{
$startDate = $this->getStartDate();
$endDate = $this->getEndDate();

return User::query()
->select(['id', 'full_name', 'birthday'])
->whereBirthday($startDate, $endDate)
->orderByBirthday();
}
class BirthdayMembersWidget extends BaseWidget
{
public Carbon $startDate;

public function mount(): void
{
$this->startDate = today();
}

protected function getTableHeaderActions(): array
{
return [
Tables\Actions\Action::make('Next')
->label(new HtmlString('»'))
->action(function () {
$this->startDate = $this->startDate->addWeek();
}),
];
}

protected function getTableQuery(): Builder
{
$startDate = $this->getStartDate();
$endDate = $this->getEndDate();

return User::query()
->select(['id', 'full_name', 'birthday'])
->whereBirthday($startDate, $endDate)
->orderByBirthday();
}
Thanks in advance!
1 Reply
Laurens
Laurens3w ago
As a workaround I'm currently dispatching a refresh event. Not 100% clean since the table gets queried twice technically though.