From abfa4cffac822e913320dc414341e272b49fc800 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=BCneyt=20=C5=9Eent=C3=BCrk?= Date: Fri, 21 Jul 2023 11:40:08 +0300 Subject: [PATCH] Category index page n+1 other category issue solved.. --- app/Traits/Categories.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/Traits/Categories.php b/app/Traits/Categories.php index c2ee8f5fb..a965169dc 100644 --- a/app/Traits/Categories.php +++ b/app/Traits/Categories.php @@ -3,6 +3,7 @@ namespace App\Traits; use App\Models\Setting\Category; +use Illuminate\Support\Facades\Cache; use Illuminate\Support\Str; trait Categories @@ -34,7 +35,10 @@ trait Categories public function getTransferCategoryId(): mixed { - return Category::other()->pluck('id')->first(); + // 1 hour set cache for same query + return Cache::remember('transferCategoryId', 60, function () { + return Category::other()->pluck('id')->first(); + }); } public function isTransferCategory(): bool