From 3574e0efdab2a5687a060b4b5186472dc72c1c7e Mon Sep 17 00:00:00 2001 From: cody <648753004@qq.com> Date: Sun, 24 Aug 2025 10:57:02 +0800 Subject: [PATCH] update --- app/Http/Controllers/Admin/SupplyDemandController.php | 4 +++- app/Models/Dialogue.php | 8 +++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/Admin/SupplyDemandController.php b/app/Http/Controllers/Admin/SupplyDemandController.php index 9cd6795..5c6a116 100755 --- a/app/Http/Controllers/Admin/SupplyDemandController.php +++ b/app/Http/Controllers/Admin/SupplyDemandController.php @@ -271,7 +271,9 @@ class SupplyDemandController extends BaseController // 当期供需发布分页 $list = SupplyDemand::with(['user', 'dialogues' => function ($query) { - $query->with('user', 'toUser')->limit(2)->orderBy('created_at', 'desc'); + $query->with(['user', 'toUser', 'messages' => function ($q) { + $q->orderBy('created_at', 'desc'); + }])->limit(2)->orderBy('created_at', 'desc'); }])->where(function ($query) use ($type) { if ($type) { $query->where('type', $type); diff --git a/app/Models/Dialogue.php b/app/Models/Dialogue.php index 19b3fd0..671b3ce 100644 --- a/app/Models/Dialogue.php +++ b/app/Models/Dialogue.php @@ -15,8 +15,14 @@ class Dialogue extends SoftDeletesModel return $this->hasOne(User::class, 'id', 'to_user_id'); } - public function supplyDemand(){ + public function supplyDemand() + { return $this->hasOne(SupplyDemand::class, 'id', 'supply_demand_id'); } + public function messages() + { + return $this->hasMany(Message::class, 'dialogue_id', 'id'); + } + }