public static function getStatisticsByCustomerID($customerID) { $details = CustomerCommodityStatistics::where('customer_id', $customerID)->get(); if ($details) { $details = $details->toArray(); } else { $details = []; } foreach ($details as &$detail) { $detail['commodity'] = Commodity::withTrashed()->find($detail['commodity_id'])->toArray(); } return $details; }