From 1a66408608fcec1d8b4c4b0731c451aa205c6449 Mon Sep 17 00:00:00 2001 From: cody <648753004@qq.com> Date: Sun, 10 Aug 2025 10:59:07 +0800 Subject: [PATCH] update --- app/Http/Controllers/Admin/SupplyDemandController.php | 4 +++- app/Models/SupplyDemand.php | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/Admin/SupplyDemandController.php b/app/Http/Controllers/Admin/SupplyDemandController.php index addd8fa..a414c21 100755 --- a/app/Http/Controllers/Admin/SupplyDemandController.php +++ b/app/Http/Controllers/Admin/SupplyDemandController.php @@ -269,7 +269,9 @@ class SupplyDemandController extends BaseController $interactionGrowthRate = $this->calculateGrowthRate($interactionCount, $prevInteractionCount); // 当期供需发布分页 - $list = SupplyDemand::where(function ($query) use ($type) { + $list = SupplyDemand::with(['messages' => function ($query) { + $query->with('user', 'toUser')->limit(2)->orderBy('created_at', 'desc'); + }])->where(function ($query) use ($type) { if ($type) { $query->where('type', $type); } diff --git a/app/Models/SupplyDemand.php b/app/Models/SupplyDemand.php index 947a3b2..b9c0860 100755 --- a/app/Models/SupplyDemand.php +++ b/app/Models/SupplyDemand.php @@ -17,6 +17,7 @@ class SupplyDemand extends SoftDeletesModel if (empty($this->file_ids)) return []; return Upload::whereIn('id', $this->file_ids)->get(); } + public function user() { return $this->hasOne(User::class, 'id', 'user_id'); @@ -27,5 +28,11 @@ class SupplyDemand extends SoftDeletesModel return $this->hasMany(SupplyDemandKeep::class, 'supply_demand_id', 'id'); } + + public function messages() + { + return $this->hasMany(Message::class, 'supply_demand_id', 'id'); + } + }