if you are executing your jobs sync then they are still executed in the same request cycle and the global request helper is still working with the same request
In a Job, Auth::user() doesn't work, but request()->ip() does! Why?
I've moved some of my functionality to jobs, in particular sending notifications and emails.
One thing I noticed right away is that in the handle() method (and subsequent blade view) Auth::user() returns null. This makes sense, because the code is passed away to the job and processed later on, so the job has no notion of a currently authenticated user.
However, request()->ip() does appear to be working and returns the IP address of the user who was responsible for invoking the job. How can this be? Similarly to Auth::user() I would have expected the job to not know what the IP address was for the user.
Please or to participate in this conversation.