Update (fix): tool count display issue

This commit is contained in:
2023-11-29 12:54:29 +08:00
parent 6580463fcb
commit 26d465e3aa
5 changed files with 27 additions and 13 deletions

View File

@@ -0,0 +1,17 @@
<?php
namespace App\Helpers\FirstParty\Cached;
use App\Models\AiTool;
use Illuminate\Support\Facades\Cache;
class Cached
{
public static function tools_count()
{
$seconds_to_remember = 599;
// Retrieve the count from the cache or count and store it if not present
return Cache::remember('tools_count_' . $seconds_to_remember, $seconds_to_remember, function () {
return AiTool::where('status','live')->count();
});
}

View File

@@ -2,6 +2,7 @@
namespace App\Http\Controllers\Front; namespace App\Http\Controllers\Front;
use App\Helpers\FirstParty\Cached\Cached;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use App\Models\AiTool; use App\Models\AiTool;
use App\Models\Category; use App\Models\Category;
@@ -14,7 +15,7 @@ class FrontDiscoverController extends Controller
{ {
public function discover(Request $request, $category_slug = null) public function discover(Request $request, $category_slug = null)
{ {
$tools_count = round_to_nearest_base(700); $tools_count_rounded = round_to_nearest_base(Cached::tools_count());
$category = null; $category = null;
@@ -49,7 +50,7 @@ public function discover(Request $request, $category_slug = null)
SEOTools::twitter(); SEOTools::twitter();
SEOTools::opengraph(); SEOTools::opengraph();
SEOTools::jsonLd(); SEOTools::jsonLd();
SEOTools::setTitle("{$tools_count} over AI Tools for you", false); SEOTools::setTitle("{$tools_count_rounded} over AI Tools for you", false);
//SEOTools::setDescription($description); //SEOTools::setDescription($description);
} }

View File

@@ -2,6 +2,7 @@
namespace App\Http\Controllers\Front; namespace App\Http\Controllers\Front;
use App\Helpers\FirstParty\Cached\Cached;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use App\Models\AiTool; use App\Models\AiTool;
use Artesaos\SEOTools\Facades\SEOMeta; use Artesaos\SEOTools\Facades\SEOMeta;
@@ -13,9 +14,11 @@ class FrontHomeController extends Controller
{ {
public function index(Request $request) public function index(Request $request)
{ {
$tools_count_rounded = round_to_nearest_base(Cached::tools_count());
$latest_ai_tools = AiTool::where('status','live')->whereNotNull('screenshot_img')->take(12)->orderBy('created_at', 'DESC')->get(); $latest_ai_tools = AiTool::where('status','live')->whereNotNull('screenshot_img')->take(12)->orderBy('created_at', 'DESC')->get();
return view('front.home', compact('latest_ai_tools')); return view('front.home', compact('latest_ai_tools','tools_count_rounded'));
} }
public function terms(Request $request) public function terms(Request $request)

View File

@@ -2,6 +2,7 @@
namespace App\View\Composers; namespace App\View\Composers;
use App\Helpers\FirstParty\Cached\Cached;
use App\Models\AiTool; use App\Models\AiTool;
use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Cache;
use Illuminate\View\View; use Illuminate\View\View;
@@ -10,14 +11,6 @@ class StatsComposer
{ {
public function compose(View $view) public function compose(View $view)
{ {
$view->with('tools_count', Cached::tools_count());
$seconds_to_remember = 599;
// Retrieve the count from the cache or count and store it if not present
$tools_count = Cache::remember('tools_count_' . $seconds_to_remember, $seconds_to_remember, function () {
return AiTool::where('status','live')->count();
});
$view->with('tools_count', $tools_count);
} }
} }

View File

@@ -48,7 +48,7 @@ class="btn btn-outline-dark text-decoration-none border-2 fw-bold rounded-pill p
@if ($tools_count > 0) @if ($tools_count > 0)
<div class="container-lg mt-3 mb-3 text-center"> <div class="container-lg mt-3 mb-3 text-center">
<a class="btn btn-primary rounded-pill px-4 breathing-effect btn-lg text-decoration-none bg-gradient" <a class="btn btn-primary rounded-pill px-4 breathing-effect btn-lg text-decoration-none bg-gradient"
href="{{ route('front.discover.home') }}">Discover More AI Tools ({{ $tools_count }})+</a> href="{{ route('front.discover.home') }}">Discover More AI Tools ({{ $tools_count_rounded }})</a>
</div> </div>
@endif @endif
@endsection @endsection