Update (fix): tool count display issue
This commit is contained in:
17
app/Helpers/FirstParty/Cached/Cached.php
Normal file
17
app/Helpers/FirstParty/Cached/Cached.php
Normal 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();
|
||||
});
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Controllers\Front;
|
||||
|
||||
use App\Helpers\FirstParty\Cached\Cached;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\AiTool;
|
||||
use App\Models\Category;
|
||||
@@ -14,7 +15,7 @@ class FrontDiscoverController extends Controller
|
||||
{
|
||||
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;
|
||||
|
||||
@@ -49,7 +50,7 @@ public function discover(Request $request, $category_slug = null)
|
||||
SEOTools::twitter();
|
||||
SEOTools::opengraph();
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Controllers\Front;
|
||||
|
||||
use App\Helpers\FirstParty\Cached\Cached;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\AiTool;
|
||||
use Artesaos\SEOTools\Facades\SEOMeta;
|
||||
@@ -13,9 +14,11 @@ class FrontHomeController extends Controller
|
||||
{
|
||||
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();
|
||||
|
||||
return view('front.home', compact('latest_ai_tools'));
|
||||
return view('front.home', compact('latest_ai_tools','tools_count_rounded'));
|
||||
}
|
||||
|
||||
public function terms(Request $request)
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\View\Composers;
|
||||
|
||||
use App\Helpers\FirstParty\Cached\Cached;
|
||||
use App\Models\AiTool;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\View\View;
|
||||
@@ -10,14 +11,6 @@ class StatsComposer
|
||||
{
|
||||
public function compose(View $view)
|
||||
{
|
||||
|
||||
$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->with('tools_count', Cached::tools_count());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ class="btn btn-outline-dark text-decoration-none border-2 fw-bold rounded-pill p
|
||||
@if ($tools_count > 0)
|
||||
<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"
|
||||
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>
|
||||
@endif
|
||||
@endsection
|
||||
|
||||
Reference in New Issue
Block a user