where('transaction_id', $search['transaction_id']); } if ($search['order_sn']) { $query->whereHas('hasOneOrder',function ($q2) use ($search) { $q2->where('order_sn', $search['order_sn']); }); } if ($search['profit_sharing'] != '') { $query->where('profit_sharing', $search['profit_sharing']); } if ($search['is_time']) { $query->whereBetween('created_at', [strtotime($search['time']['start']), strtotime($search['time']['end'])]); } return $query; } public function hasOneOrder() { return $this->hasOne(Order::class,'id','order_id'); } }