F
Filament15mo ago
Vinny

Prevent select option re-rendering in SelectInput

Hi, I am using a SelectInput that looks something like this
Select::make('test')->options(Post::query()->get()->pluck('id, title')
Select::make('test')->options(Post::query()->get()->pluck('id, title')
I am using this in a Wizard and my problem is that I have about 6-7 selects that rely on DB queries. This causes issues anytime I go between pages in the Wizard and the form ends up becoming very slow because it runs the DB query for the select options if there is any kind of validation, live state update, or change in wizard step. I would like to make it so that I only have to query the DB once for the select options, on page load. I could store the select options in public variable on the Form and call the query only once, in the mount method, and passing the variable as the options parameter in the selects. but I was wondering if there was a different way to do this where I could tell the Select component to not re-run the options query after the initial page load.
2 Replies
Patrick Boivin
Patrick Boivin15mo ago
Would the Laravel cache work for you in this case? I'm thinking you could cache each query (for the subsequent requests) and make sure to clear the cache on page load.
Vinny
VinnyOP15mo ago
I have considered that option. I am willing to do it if there is no straightforward way to prevent options from reloading everytime.
Want results from more Discord servers?
Add your server