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

TheRabber's avatar

Laravel inertia scope for client selection

Hey, I wonder what the best practice for this use case would be: I have an application where the user is asigned to one or many groups, now my idea is to have a drop down in the front end where he can select for which group he wants to see data (models are linked via polymorphic relationship to the group) or if he wants to see data for all groups in the application.

My first idea was to store the information inside the session and apply global scopes to all my models based on the data stored in the session and if selected "all" just do an early return there.

But that feels kinda hacky. Do you guys have a better idea on how it could be implemented?

Thanks :)

0 likes
8 replies
gych's avatar
gych
Best Answer
Level 29

Using session to store the selected preference to view data for all groups or just a specific group is a good solution. When a user visits a page, check which preference is stored in session and return the filtered data to the front end.

2 likes
TheRabber's avatar

Thanks, so I will go that way :)

As I'm new to inertia, what would be the best way to set the session? Usually I would create an axios request to some endpoint and store the session data there. If this is still the best option: how would I secure that endpoint properly? Or is there a build in thing in inertia?

1 like
TheRabber's avatar

@vincent15000 Yes, already using it to build parts of the menue dynamically. But how does that help with setting the session from the frontend perspective?

1 like

Please or to participate in this conversation.