I am trying to run some in my application, i was not getting the expected result, so i decided trace where the error was coming from by commenting out code line by line in my controller, within the function. I finally narrowed it down to this area:
DB::beginTransaction();
try
{
// Getting mpower transaction record
$payment = PaymentTransaction::select('id', 'invoice_reference_code', 'transaction_token')
->where('transaction_token', $transaction_token)
->where('is_verified', 0)
->first();
// If found, setting transaction to verified
$payment->is_verified = 1;
$payment->save();
// Getting purchase invoice details
$invoice_details = InvoiceDetails::where('reference_code', $payment->invoice_reference_code)
->where('is_verified', 0)
->first();
// If found, setting invoice to verified
$invoice_details->is_verified = 1;
$invoice_details->save();
DB::commit();
}
catch (\Exception $e)
{
return [
'code' => 300,
'message' => $e->getMessage(),
'data' => []
];
}
The error being thrown is:
Creating default object from empty value
The error seems to be thrown at this line:
$invoice_details->is_verified = 1;
I have checked $payment and it does indeed return data.
I really cannot tell what i am missing here.