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

alex_hill's avatar

storing model in the session, is there a better way?

I am building an app where a user may have multiple Jobs (although most will have only one). When a user does have multiple they are asked to select which one they want to look at post login. At this point the site (navigation etc)is purely dependant on the selected job with the exception of a drop down in the nav to switch jobs.

Currently i store the results of the job in the session and refer to the session version of the job throughout the code. I feel like this isn't the best approach. What's the best way of remembering which job is "active". Id like to avoid coding it into the url.

0 likes
3 replies
jekinney's avatar

Set an active Boolean field for an active job? Cache the results and associate with the auth facade you you can call auth()->user()->somejob

henrique's avatar

I've done something similar once, I just stored it at the User table. Then use Auth::user()->active_job_id to access it.

alex_hill's avatar

Thanks guys - I knew there was a better way :)

Please or to participate in this conversation.