How can I automatically launch a function when user enters a Resource list page?

I need to update some data before users access the mediaResource list page (table). What would be a correct approach to automatically launch the function I need as soon as user enters that url (https://apps.geslem.com/media) ? For the moment, I have put a button that users have to click to run the funcion:
->HeaderActions([
Action::make('Actualizar')
->color('amber')
->action( function () {
(new MediaService())->recalculaMediaNumExp();
}),
]
->HeaderActions([
Action::make('Actualizar')
->color('amber')
->action( function () {
(new MediaService())->recalculaMediaNumExp();
}),
]
Any ideas, please? Tks in advance.
2 Replies
dissto
dissto3mo ago
Perhaps via the mount function on the Listmyresource class. But that's seems like an atypical approach (changing all the records before accessing them in the index list)
Albert Lens
Albert Lens3mo ago
Yes, I know it is a "horrible" provisional solution till I can find when the error happens. It has to be launched through serveral observers but not all of them are launching the function correctly and I have to investigate a bit more to find the error. Thanks for your approach. I put the function inside the table function (which is always called when you go to the listMyResource) and it is working fine:
public static function table(Table $table): Table
{
(new MediaService())->recalculaMediaNumExp();
return $table
->columns([
public static function table(Table $table): Table
{
(new MediaService())->recalculaMediaNumExp();
return $table
->columns([
Thanks for your help.