How to hard page reload after Update button's action is done?

The current state of the Update button on the edit page is that it doesn't hard reload the page. But I need that somehow. How to do that? Basically I want that after the update the whole page is hard reloaded - like when you presse cmd + R or ctrl + R in browser.
Solution:
``` protected function getFormActions(): array { return [...
Jump to solution
8 Replies
Wirkhof
WirkhofOP9mo ago
Currenty it just shows the toast and nothing reloads. Also, I have a custom button on the Edit page:
Action::make('orderPending')
->action(function () {
$this->data['status'] = 'pending';
return $this->save();
})
->label('Pending'),
Action::make('orderPending')
->action(function () {
$this->data['status'] = 'pending';
return $this->save();
})
->label('Pending'),
and it is behaving the same, I need to manually reload the Edit page to see the changes. Pressing the button just save the change in the DB but doesn't reload the page itself. Can I add something to this Action::make code to make it reload the page after $this->save() is finished? It could be a hard refresh as I said. But if it's possible with livewire navigate type of refresh that's great. Thank you in advance for any help. If I try this:
Action::make('orderPending')
->action(function () {
$this->data['status'] = 'pending';
$this->save();

$this->refreshFormData([]);
})
->label('Pending'),
Action::make('orderPending')
->action(function () {
$this->data['status'] = 'pending';
$this->save();

$this->refreshFormData([]);
})
->label('Pending'),
it seems to refresh the form on save and I see the status changed after the click. But the buttonpanel doesn't reflect the change I setup in the getFormActions method on the Edit page where I do an if condition and displaying custom buttons based on the state. And it seems that this "getFormActions" method is not reloaded on each mouse click on buttons there. Perhaps I can force it to reload the buttons section (Save, Cancel, ...) on each Edit page? Or the easiest way would be a hard page reload 😉 Is it some command to stick inside ->action() to do the hard page reload after the saving part is done?
Wirkhof
WirkhofOP9mo ago
Stack Overflow
How on form saving fresh header button hidden condition?
In laravel 10 / filamentphp 3 app I use status selection input with several options and depending on current status button in getHeaderActions() I need to show/hide button, which opens modal dialog...
Wirkhof
WirkhofOP9mo ago
Caching?
Dan Harrin
Dan Harrin9mo ago
send getFormActions i know how to force a page reload but i bet you dont need it
Wirkhof
WirkhofOP9mo ago
protected function getFormActions(): array
{

if ($this->record->status == 'pending') {
return [
$this->getSaveFormAction(),
$this->getCancelFormAction(),
Action::make('orderPending')
->action(function () {
$this->data['status'] = 'pending';
$this->save();
$this->refreshFormData([]);
return;
})
];
} else {
return [
$this->getSaveFormAction(),
$this->getCancelFormAction(),
];
}
}
protected function getFormActions(): array
{

if ($this->record->status == 'pending') {
return [
$this->getSaveFormAction(),
$this->getCancelFormAction(),
Action::make('orderPending')
->action(function () {
$this->data['status'] = 'pending';
$this->save();
$this->refreshFormData([]);
return;
})
];
} else {
return [
$this->getSaveFormAction(),
$this->getCancelFormAction(),
];
}
}
Solution
Dan Harrin
Dan Harrin9mo ago
protected function getFormActions(): array
{

return [
$this->getSaveFormAction(),
$this->getCancelFormAction(),
Action::make('pending')
->action(function () {
$this->data['status'] = 'pending';
$this->save();
$this->refreshFormData([]);
return;
})
->visible(fn () => $this->record->status == 'pending')
];
}
protected function getFormActions(): array
{

return [
$this->getSaveFormAction(),
$this->getCancelFormAction(),
Action::make('pending')
->action(function () {
$this->data['status'] = 'pending';
$this->save();
$this->refreshFormData([]);
return;
})
->visible(fn () => $this->record->status == 'pending')
];
}
Wirkhof
WirkhofOP9mo ago
Hmm, thanks. Interesting, maybe I don't even need the if condition and it can be all done via visible(). We will see. Thanks. One question though. Do I need to put return; at the end of code inside ->action()? Which one is the correct form? This one:
->action(function () {
$this->data['status'] = 'pending';
$this->save();
$this->refreshFormData([]);
return;
})
->action(function () {
$this->data['status'] = 'pending';
$this->save();
$this->refreshFormData([]);
return;
})
or this one:
->action(function () {
$this->data['status'] = 'pending';
$this->save();
$this->refreshFormData([]);

})
->action(function () {
$this->data['status'] = 'pending';
$this->save();
$this->refreshFormData([]);

})
?
Want results from more Discord servers?
Add your server