From 4e23348a3f4193cf4398c377ef5416b9596b65b9 Mon Sep 17 00:00:00 2001 From: liapples Date: Fri, 23 Jul 2021 11:33:32 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8E=BB=E6=8E=89=E7=8C=9C=E4=BD=A0=E5=96=9C?= =?UTF-8?q?=E6=AC=A2=EF=BC=8C=E4=BF=AE=E6=94=B9=E4=BA=BA=E6=B0=94=E7=88=86?= =?UTF-8?q?=E6=AC=BE=E7=9A=84=E8=B0=83=E7=94=A8=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/Api/IndexController.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/Http/Controllers/Api/IndexController.php b/app/Http/Controllers/Api/IndexController.php index d6da63e..34067eb 100644 --- a/app/Http/Controllers/Api/IndexController.php +++ b/app/Http/Controllers/Api/IndexController.php @@ -5,7 +5,7 @@ use App\Http\Controllers\Controller; use App\Models\Advertising; use App\Models\Channel; use App\Models\Notice; -use App\Models\Product; +use App\Models\AgentProduct; use App\Models\Slide; use App\Models\UserChannel; @@ -34,10 +34,11 @@ class IndexController extends Controller $home_ad1 = Advertising::where('agent_id', $this->agent_id)->value('picture'); # 人气爆款 - $hots = Product::get(['title', 'price', 'original_price', 'pictures', 'sale']); - - # 猜你喜欢 -// $guess = Product::get(['title', 'price', 'original_price', 'pictures', 'sale']); +// $hots = AgentProduct::select(['title', 'price', 'original_price', 'pictures'])->get(); + $hots = AgentProduct::query() + ->select('id', 'sale', 'product_id', 'price', 'original_price') //必须查询product_id才能with + ->with(['product' => fn ($query) => $query->select('id', 'title', 'pictures')]) //必须查询ID才能正常查询 + ->limit(6)->get(); return $this->success([ 'slide' => $slide, @@ -45,7 +46,6 @@ class IndexController extends Controller 'my_channels' => $my_channels, 'home_ad1' => $home_ad1, 'hots' => $hots, -// 'guess' => $guess, ]); } }