*/ protected $guarded = []; /** * @var array */ protected $casts = [ 'cover' => 'boolean', 'backdrop' => 'boolean', 'genres_id' => 'integer', 'releasedate' => 'date', ]; /** * Get the genre for this game. * * @return BelongsTo */ public function genre(): BelongsTo { return $this->belongsTo(Genre::class, 'genres_id'); } /** * Get the releases for this game. * * @return HasMany */ public function releases(): HasMany { return $this->hasMany(Release::class, 'gamesinfo_id'); } /** * Get the cover image path. */ public function getCoverPath(): ?string { if (! $this->cover) { return null; } $path = config('nntmux_settings.covers_path').'/games/'.$this->id.'.webp'; if (file_exists($path)) { return $path; } $legacyPath = preg_replace('/\.webp$/', '.jpg', $path); return is_string($legacyPath) && file_exists($legacyPath) ? $legacyPath : null; } /** * Get the backdrop image path. */ public function getBackdropPath(): ?string { if (! $this->backdrop) { return null; } $path = config('nntmux_settings.covers_path').'/games/'.$this->id.'-backdrop.webp'; if (file_exists($path)) { return $path; } $legacyPath = preg_replace('/\.webp$/', '.jpg', $path); return is_string($legacyPath) && file_exists($legacyPath) ? $legacyPath : null; } }