Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

kriyapedo's avatar

Best way to "lazy" load into a component using Inertia and Laravel?

Hi!

So I have in my web apps severals components that should be able to work standalone.

Let's say I have a "group" picker on a student. The student might have the option to change its group, the teacher might have the option to change its group and the administration might have this option too.

If it's on 5 different pages, I would need to make the query "load all the groups" 5 different time in 5 different controllers.

Would there be a way to tell Inertia "when there is the component XYZ, retrieve all the groups only for this component" without having to include it in each page where it is loaded?

0 likes
1 reply
vincent15000's avatar

Is your front coded with VueJS ? ReactJS ?

Well in both cases the solution is to use a store like pinia for VueJS and load the groups when the application is loading. Then instead of querying the database to retrieve the groups, you just have to retrieve the existing groups in the store.

https://pinia.vuejs.org/

I think that the equivalent for ReactJS is redux.

https://redux.js.org/

Please or to participate in this conversation.