I have a number of places where I rely on Illuminate\Auth\Guard to give the the current user. I haven't had any issues until about an hour ago when I decided it was time to start using a queue to speed the site up some.
Problem:
When a user updates a job task I need examine all of that jobs tasks to update the jobs overall status accordingly, I've already written the task event handler and everything works well. When I queue the same event I run into errors like my RecordsActivity trait not knowing which user just updated the job status, or my TaskRequirementsProvider not knowing which account settings should be used.
I Came up with two solutions one being much easier than the second.
Solution 1: I can go around to everywhere that expects a user to be logged in and find another way to make the user accessible.
EX: set the account id on the provider before asking for required tasks
This could take quite a while, Most of the software needs to know who is logged in and I always just ask guard for the user, This is extremely convenient and this is the first issue I have had with doing it this way.
Solution 2. I can just include the user in the event and set them as the current user in the handler.
This definitely handles the current issues but are there any caveats to this? I've never really set the user except to allow super users to log into another persons account. I pretty much used the default authentication scaffolding and haven't had to deal much with managing the guard state so a am a bit skeptical how this method may be viewed by other developers.
If anyone has time ( after reading this book >.< ) and would care to share some insight into the pros and cons of either solution it would be much appreciated.