From 8ab13024c73a3813e5ad9395ae53c391173dd202 Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 30 May 2023 23:56:13 +0200 Subject: [PATCH] Add fn for prepared (post link) Data injection --- app/Http/Controllers/IGDBController.php | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/IGDBController.php b/app/Http/Controllers/IGDBController.php index b161d05..92ad969 100644 --- a/app/Http/Controllers/IGDBController.php +++ b/app/Http/Controllers/IGDBController.php @@ -11,10 +11,10 @@ use Illuminate\Support\Str; class IGDBController extends Controller { public static function getGameDetails(string $slug) - { + {// TODO Weiter bauen und weiter Details für Link aufbröseln $game = Http::withHeaders(config('services.igdb'))->withBody( - "fields *, name, cover.url, first_release_date, total_rating_count, platforms.abbreviation, rating, rating_count, slug, involved_companies.company.name, genres.name, aggregated_rating, summary, websites.*, videos.*, screenshots.*, similar_games.*, similar_games.cover.url, similar_games.platforms.abbreviation; - where slug=\"{$slug}\";", + "fields *,age_ratings.*, age_ratings.*, name, cover.url, first_release_date, total_rating_count, platforms.abbreviation, rating, rating_count, slug, involved_companies.company.name, genres.name, aggregated_rating, summary, websites.*, videos.*, screenshots.*, similar_games.*, similar_games.cover.url, similar_games.platforms.abbreviation; + where slug=\"{$slug}\";", "text/plain" )->post('https://api.igdb.com/v4/games') ->json(); @@ -25,6 +25,19 @@ class IGDBController extends Controller return $game[0]; } + public static function getPreparedGameDetails(string $slug) + { + $game = IGDBController::getGameDetails($slug); + $rating_ids = []; + foreach ($game['age_ratings'] as $rating){ + array_push($rating_ids, $rating['rating']); + } + $game['age_ratings'] = $rating_ids; + abort_if(!$game, 404); + #dd($game); + + return $game; + } public static function searchGameByName(string $name) {