Add follow system, activity feed, notifications, sitemap, caching, Scout search
This commit is contained in:
@@ -6,6 +6,7 @@ use App\Models\Game;
|
||||
use App\Models\Genre;
|
||||
use App\Models\Platform;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class GameController extends Controller
|
||||
{
|
||||
@@ -53,7 +54,10 @@ class GameController extends Controller
|
||||
$userLists = auth()->user()->lists()->get(['id', 'title']);
|
||||
}
|
||||
|
||||
return view('games.show', compact('game', 'userGame', 'userReview', 'userLists'));
|
||||
$response = view('games.show', compact('game', 'userGame', 'userReview', 'userLists'));
|
||||
return auth()->check()
|
||||
? $response
|
||||
: response($response)->header('Cache-Control', 'public, max-age=300');
|
||||
}
|
||||
|
||||
public function search(Request $request)
|
||||
@@ -62,23 +66,19 @@ class GameController extends Controller
|
||||
$games = collect();
|
||||
|
||||
if (strlen($q) >= 2) {
|
||||
$games = Game::published()
|
||||
->where('title', 'like', "%{$q}%")
|
||||
->orderByDesc('rating_count')
|
||||
->limit(20)
|
||||
->get();
|
||||
$games = Game::search($q)->get()->filter(fn($g) => $g->status === 'published');
|
||||
}
|
||||
|
||||
if ($request->expectsJson()) {
|
||||
return response()->json($games->map(fn($g) => [
|
||||
'id' => $g->id,
|
||||
'title' => $g->title,
|
||||
'slug' => $g->slug,
|
||||
'cover_thumb' => $g->cover_thumb_url,
|
||||
'release_year' => $g->release_year,
|
||||
'rating_avg' => $g->rating_avg,
|
||||
'url' => route('games.show', $g),
|
||||
]));
|
||||
return response()->json($games->take(6)->map(fn($g) => [
|
||||
'id' => $g->id,
|
||||
'title' => $g->title,
|
||||
'slug' => $g->slug,
|
||||
'cover_thumb' => $g->cover_thumb_url,
|
||||
'release_year' => $g->release_year,
|
||||
'rating_avg' => $g->rating_avg,
|
||||
'url' => route('games.show', $g),
|
||||
])->values());
|
||||
}
|
||||
|
||||
return view('games.search', compact('games', 'q'));
|
||||
@@ -86,24 +86,30 @@ class GameController extends Controller
|
||||
|
||||
public function topRated(Request $request)
|
||||
{
|
||||
$games = Game::published()
|
||||
->where('rating_count', '>=', 1)
|
||||
->orderByDesc('rating_avg')
|
||||
->orderByDesc('rating_count')
|
||||
->paginate(24)
|
||||
->withQueryString();
|
||||
$page = $request->get('page', 1);
|
||||
$games = Cache::remember("games.top_rated.{$page}", 300, fn() =>
|
||||
Game::published()
|
||||
->where('rating_count', '>=', 1)
|
||||
->orderByDesc('rating_avg')
|
||||
->orderByDesc('rating_count')
|
||||
->paginate(24)
|
||||
->withQueryString()
|
||||
);
|
||||
|
||||
return view('games.top-rated', compact('games'));
|
||||
}
|
||||
|
||||
public function newReleases(Request $request)
|
||||
{
|
||||
$games = Game::published()
|
||||
->whereNotNull('release_date')
|
||||
->where('release_date', '<=', now())
|
||||
->orderByDesc('release_date')
|
||||
->paginate(24)
|
||||
->withQueryString();
|
||||
$page = $request->get('page', 1);
|
||||
$games = Cache::remember("games.new_releases.{$page}", 300, fn() =>
|
||||
Game::published()
|
||||
->whereNotNull('release_date')
|
||||
->where('release_date', '<=', now())
|
||||
->orderByDesc('release_date')
|
||||
->paginate(24)
|
||||
->withQueryString()
|
||||
);
|
||||
|
||||
return view('games.new-releases', compact('games'));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user