Support the ongoing development of Laravel.io →
Authentication

Hi, gang. I am new to Laravel and I am trying to figure out the best way to accomplish something which I thought would be simple.

I have a class that requires a user id as a parameter. I have it registered as a singleton in the service container. I cannot figure out how to provide the current logged-in user's id to the singleton unless I use a method on the class to pass Auth::id() to the class as a parameter from the controller's method. I have tried using middleware but Auth::id() seems to be empty until after the controller's first non-constructor method gets hit. Does anybody know a way for me to accomplish my goal?

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

roric32 roric32 Joined 6 Jan 2017

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.