首页 > 解决方案 > production.ERROR:从空值创建默认对象 {"exception":"[object]

问题描述

我收到错误生产。错误:

从空值创建默认对象 {"exception":"[object]

但我无法检测到错误。

$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();
}

标签: laravel

解决方案


$data未设置 - 您的查询约束未找到记录并返回null。然后,您尝试设置值$data->amount,但由于$data不存在,因此会出错。

确保您的查询是正确的并加载存在的存款记录,否则设置$data = new Deposit为创建新记录。


推荐阅读