*/ protected $guarded = []; // ======================================== // Relationships // ======================================== /** * Get the genre for the console info. * * @return BelongsTo */ public function genre(): BelongsTo { return $this->belongsTo(Genre::class, 'genres_id'); } /** * Get the releases for the console info. * * @return HasMany */ public function releases(): HasMany { return $this->hasMany(Release::class, 'consoleinfo_id'); } // ======================================== // Query Scopes // ======================================== /** * Scope a query to only include consoles with covers. */ public function scopeWithCover(mixed $query): mixed { return $query->where('cover', 1); } /** * Scope a query to only include consoles for a specific platform. */ public function scopeForPlatform(mixed $query, string $platform): mixed { return $query->where('platform', $platform); } // ======================================== // Static Helper Methods // ======================================== /** * Get console info by ID with genre. */ public static function getWithGenre(int $id): ?self { return static::query() ->where('consoleinfo.id', $id) ->select('consoleinfo.*', 'genres.title as genres') ->leftJoin('genres', 'genres.id', '=', 'consoleinfo.genres_id') ->first(); } /** * Find by ASIN. */ public static function findByAsin(string $asin): ?self { return static::where('asin', $asin)->first(); } }