2

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.

1 Answer 1

3

Please check if the query has returned a result to $invoice_details. If it has returned empty then initialize an object likewise:

$invoice_details   = new InvoiceDetails;

Then try calling the save function.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.