0

I am getting error production.ERROR:

Creating default object from empty value {"exception":"[object]

but I can not detect the error.

$data = Deposit::where('status',0)->where('wallet', $request->address)->orderBy('id', 'DESC')->first();

if ($request->status>=1 || $request->status==2) 
{
     $data = Deposit::where('status',0)->where('wallet', $request->address)->orderBy('id', 'DESC')->first();
     $data->amount = $request->amount; // Here IS ERROR
     $data->status= 1;
     $data->update();
}
3
  • dont have amount in $request, dd($request) to check you getting amount or not from request Commented Aug 7, 2019 at 6:06
  • @KaranSadana this is IPN off payment gateway . i am requesting Commented Aug 7, 2019 at 6:10
  • @KaranSadana and it is adding amount also in database but why error Commented Aug 7, 2019 at 6:11

2 Answers 2

1

$data is not being set - your query constraints are not finding a record and returning null. You're then trying to set value $data->amount but as $data does not exist it's erroring.

Ensure that your query is correct and loading a Deposit record that exists, otherwise set $data = new Deposit to create a new record.

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

Comments

0

You can try like

$data = Deposit::where('status',0)->where('wallet', $request->address)->first();
if(!empty($data)){
    $data->amount = $request->amount;
    $data->status= 1;
    $data->save();
}

As you are using first() there is a possibility that the object is empty. So when you are trying to update that empty object you are getting this error.

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.