'Laravel queue processed event listener doesn't contain my user

I'm using the Laravel 8 job and queue system. I'm dispatching a job called FetchBeamData within one of my controllers and am passing it the currently logged in user.

Then, inside of my AppServiceProvider I'm using the JobProcessed event that will trigger some custom functionality.

But when I unserialize my payload, I'm not seeing my user at all in there, what am I missing?

My user is passed into my job's constructor as an optional argument:

/**
 * Create a new job instance.
 *
 * @return void
 */
public function __construct($beam, $user = null)
{
    $this->beam = $beam;
    $this->user = $user;
}

And when I dispatch the job, I run:

FetchBeamData::dispatch($beam, Auth::user());

Inside of my listener, I expect to see the user in there:

/**
 * Bootstrap any application services.
 *
 * @return void
 */
public function boot()
{
    Queue::after(function (JobProcessed $event) {
        $payload = $event->job->payload();

        Log::debug('=== AFTER ===', [
            'connectionName' => $event->connectionName,
            'job' => $event->job,
            'payload' => unserialize($payload['data']['command'])
        ]);
    });
}

What am I missing to access this, the current output is:

{
   "connectionName":"database",
   "job":{
      "Illuminate\\Queue\\Jobs\\DatabaseJob":[
         
      ]
   },
   "payload":{
      "App\\Jobs\\FetchBeamData":{
         "job":null,
         "connection":null,
         "queue":"on-demand-runs-now",
         "chainConnection":null,
         "chainQueue":null,
         "chainCatchCallbacks":null,
         "delay":null,
         "afterCommit":null,
         "middleware":[
            
         ],
         "chained":[
            
         ]
      }
   }
}


Solution 1:[1]

this should do the trick

public $beam;
public $user;

public function __construct($beam, $user = null)
{
  $this->beam = $beam;
  $this->user = $user;

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 incontriamoci.xxx