It looks like the issue might be related to the way you're retrieving the record from the database. Specifically, it seems that the content column is not being retrieved. This could be due to a few reasons, such as the column not being selected or an issue with the model's $fillable or $hidden properties.
Here are a few steps to troubleshoot and resolve the issue:
-
Check Model's
$fillableProperty: Ensure that thecontentcolumn is included in the$fillableproperty of yourPdfReportmodel.class PdfReport extends Model { protected $fillable = [ 'pdf_uuid', 'status', 'fromDate', 'toDate', 'user_id', 'type', 'content', ]; } -
Check Model's
$hiddenProperty: Ensure that thecontentcolumn is not included in the$hiddenproperty of yourPdfReportmodel.class PdfReport extends Model { protected $hidden = [ // 'content', // Make sure this line is not hiding the content column ]; } -
Retrieve the Record Properly: When retrieving the record, use the
first()method directly instead of chainingget()andfirst(). This ensures you get a single instance of the model.$item = PdfReport::where('id', $this->reportId)->first(); Log::info(json_encode($item)); -
Check Database Schema: Ensure that the
contentcolumn exists in your database schema and that it is being populated correctly during the insert operation. -
Debugging: Add some debugging statements to ensure that the
contentcolumn is being set correctly during the insert operation.
Here is the revised code with the above considerations:
$report = PdfReport::create(
[
'pdf_uuid' => Str::uuid(),
'status' => PdfReport::PENDING,
'fromDate' => date('Y-m-d', strtotime($request->fromDate)),
'toDate' => date('Y-m-d', strtotime($request->toDate)),
'user_id' => $request->user()->id,
'type' => $pdftype,
'content' => json_encode($content),
]
);
PdfReportJob::dispatch($report->id);
And in your Job class:
$item = PdfReport::where('id', $this->reportId)->first();
Log::info(json_encode($item));
By following these steps, you should be able to retrieve the content column correctly. If the issue persists, double-check your database schema and ensure that the content column is being populated as expected.