$yesterday, "un_weigh_count" => 0, "total_count" => 0, "measuring_machine_id" => 0, "owner_id" => 0 ]; $model = OrderPackageCountingRecord::query()->create($obj); Cache::put("weight.".$yesterday, $obj); }else{ $objs = []; foreach ($result as $v){ $obj = [ "targeted_at" => $v->date, "un_weigh_count" => $v->count, "total_count" => $v->total, "measuring_machine_id" => $v->measuring_machine_id, "owner_id" => $v->owner_id ]; $model = OrderPackageCountingRecord::query()->create($obj); array_push($objs, $obj); } Cache::put("weight.".$yesterday, $objs); } } }