catalogMetalIds(); $records = Order::with([ 'customer', 'product' => static function ($q) { $q->withTrashed()->select(['id', 'title', 'unit', 'metal_id', 'group_type', 'amount', 'trade_by_quantity', 'direct_price']); }, 'transactions.product' => static function ($q) { $q->withTrashed()->select(['id', 'title', 'unit', 'metal_id', 'group_type', 'amount', 'trade_by_quantity', 'direct_price']); }, ]); TableEngine::create($records, $request->all()) ->initSearch(['customer.name']) ->select([ '*',Order::$SELECT_STS_STR ])->export($records); if (isset($records['rows'])) { foreach ($records['rows'] as &$row) { $balanceReport->enrichOrderTableRow($row, $catalogMetalIds); } unset($row); } $records['catalogMetals'] = $balanceReport->catalogMetalsMeta(); return response()->json($records); } public function singleOrderTable(Request $request){ $balanceReport = app(BalanceReportService::class); $catalogMetalIds = app(WalletBalanceService::class)->catalogMetalIds(); $records = Order::with([ 'customer', 'product' => static function ($q) { $q->withTrashed()->select(['id', 'title', 'unit', 'metal_id', 'group_type', 'amount', 'trade_by_quantity', 'direct_price']); }, 'transactions.product' => static function ($q) { $q->withTrashed()->select(['id', 'title', 'unit', 'metal_id', 'group_type', 'amount', 'trade_by_quantity', 'direct_price']); }, ])->where('type',2); TableEngine::create($records, $request->all()) ->initSearch(['customer.name']) ->select([ '*',Order::$SELECT_STS_STR ])->export($records); if (isset($records['rows'])) { foreach ($records['rows'] as &$row) { $balanceReport->enrichOrderTableRow($row, $catalogMetalIds); } unset($row); } $records['catalogMetals'] = $balanceReport->catalogMetalsMeta(); return response()->json($records); } }