Expand IGDB data: collections, game modes, themes, perspectives, videos, websites, age ratings, similar games; add backfill command

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Mark
2026-06-01 00:24:05 +03:00
co-authored by Claude Sonnet 4.6
parent 0eab3e8dbf
commit 2a724c0ae2
21 changed files with 768 additions and 57 deletions
+16
View File
@@ -0,0 +1,16 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
class Collection extends Model
{
protected $fillable = ['igdb_id', 'name', 'slug'];
public function games(): HasMany
{
return $this->hasMany(Game::class);
}
}
+47 -4
View File
@@ -3,6 +3,7 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Support\Facades\Cache;
@@ -15,14 +16,16 @@ class Game extends Model
use HasSlug, Searchable;
protected $fillable = [
'igdb_id', 'slug', 'title', 'summary', 'cover_url', 'cover_thumb_url',
'igdb_id', 'slug', 'title', 'summary', 'storyline', 'cover_url', 'cover_thumb_url',
'release_date', 'release_year', 'rating_avg', 'rating_count', 'review_count',
'library_count', 'status',
'library_count', 'status', 'collection_id', 'age_rating_pegi', 'age_rating_esrb',
'aggregated_rating', 'aggregated_rating_count', 'similar_game_igdb_ids',
];
protected $casts = [
'release_date' => 'date',
'rating_avg' => 'decimal:2',
'release_date' => 'date',
'rating_avg' => 'decimal:2',
'similar_game_igdb_ids' => 'array',
];
public function getSlugOptions(): SlugOptions
@@ -32,6 +35,11 @@ class Game extends Model
public function getRouteKeyName(): string { return 'slug'; }
public function collection(): BelongsTo
{
return $this->belongsTo(Collection::class);
}
public function genres(): BelongsToMany
{
return $this->belongsToMany(Genre::class, 'game_genre');
@@ -67,6 +75,41 @@ class Game extends Model
return $this->hasMany(GameComment::class);
}
public function gameModes(): BelongsToMany
{
return $this->belongsToMany(GameMode::class, 'game_game_mode');
}
public function themes(): BelongsToMany
{
return $this->belongsToMany(Theme::class, 'game_theme');
}
public function playerPerspectives(): BelongsToMany
{
return $this->belongsToMany(PlayerPerspective::class, 'game_player_perspective');
}
public function videos(): HasMany
{
return $this->hasMany(GameVideo::class);
}
public function websites(): HasMany
{
return $this->hasMany(GameWebsite::class);
}
public function similarGames(): BelongsToMany
{
return $this->belongsToMany(
Game::class,
'similar_games',
'game_id',
'similar_game_id'
);
}
public function toSearchableArray(): array
{
return [
+16
View File
@@ -0,0 +1,16 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
class GameMode extends Model
{
protected $fillable = ['igdb_id', 'name', 'slug'];
public function games(): BelongsToMany
{
return $this->belongsToMany(Game::class, 'game_game_mode');
}
}
+26
View File
@@ -0,0 +1,26 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class GameVideo extends Model
{
protected $fillable = ['game_id', 'igdb_id', 'name', 'video_id'];
public function game(): BelongsTo
{
return $this->belongsTo(Game::class);
}
public function getYoutubeUrlAttribute(): string
{
return "https://www.youtube.com/watch?v={$this->video_id}";
}
public function getYoutubeEmbedUrlAttribute(): string
{
return "https://www.youtube.com/embed/{$this->video_id}";
}
}
+31
View File
@@ -0,0 +1,31 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class GameWebsite extends Model
{
protected $fillable = ['game_id', 'category', 'url'];
public const CATEGORY_LABELS = [
1 => 'Official',
2 => 'Wikia',
3 => 'Wikipedia',
9 => 'YouTube',
13 => 'Steam',
16 => 'Epic Games',
17 => 'GOG',
];
public function game(): BelongsTo
{
return $this->belongsTo(Game::class);
}
public function getLabelAttribute(): string
{
return self::CATEGORY_LABELS[$this->category] ?? 'Website';
}
}
+16
View File
@@ -0,0 +1,16 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
class PlayerPerspective extends Model
{
protected $fillable = ['igdb_id', 'name', 'slug'];
public function games(): BelongsToMany
{
return $this->belongsToMany(Game::class, 'game_player_perspective');
}
}
+16
View File
@@ -0,0 +1,16 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
class Theme extends Model
{
protected $fillable = ['igdb_id', 'name', 'slug'];
public function games(): BelongsToMany
{
return $this->belongsToMany(Game::class, 'game_theme');
}
}