Home > database >  how to get specific data from the jobs payload in laravel?
how to get specific data from the jobs payload in laravel?

Time:12-08

I need to unserialize the payload data of failed jobs how I can able to get specific data from that failed Jobs I tried most of the things like

   $j = App\Models\FailedJobs::select('payload')->get();
   $raw = json_decode($j[0]->payload)->data->command;
   $cm = unserialize($raw);

result of this example

App\Jobs\FailedJobs^ {#1021
 timeout: 7200
 tries: 1
#msg: array:3 [
"user_email" => Illuminate\Support\Collection^ {#1019
  #items: array:8 [
    0 => " [email protected]"
  ]
 }
]
#job: null
 connection: null
 queue: null
 chainConnection: null
 chainQueue: null
 delay: null
 chained: []
}

How I can able access user_email from this payload object also tried with foreach but no luck

  public function getFailedJob()
{
    #Fetch all the failed jobs
   
    $data = [];
    
      $j = App\Models\FailedJobs::select('payload')->get();
      $raw = json_decode($j[0]->payload)->data->command;
      $cm = unserialize($raw);
    foreach ($cm as $job) {
      dd($job)
    }

output of this

7200
1
null
null
null
null
null
[]

the msg object is not accessible ..

CodePudding user response:

try this:

$job = App\Models\FailedJobs::find($id);
$payload = json_decode($job->payload);
$data = unserialize($payload->data->command);

CodePudding user response:

The property starts with # is property, you can access it by ReflectionProperty :

$property = new ReflectionProperty($cm, 'msg');
$property->setAccessible(true);
dump($property->getValue($cm));
  • Related