70 lines
1.5 KiB
PHP
70 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Features\Games\Models;
|
|
|
|
use App\Features\Consoles\Models\Console;
|
|
use App\Features\Settings\Models\SaveFile;
|
|
use Database\Factories\GameFactory;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Support\Str;
|
|
|
|
class Game extends Model
|
|
{
|
|
/** @use HasFactory<GameFactory> */
|
|
use HasFactory;
|
|
|
|
protected static ?string $factory = GameFactory::class;
|
|
|
|
protected $fillable = [
|
|
'console_id',
|
|
'title',
|
|
'slug',
|
|
'igdb_id',
|
|
'tgdb_id',
|
|
'description',
|
|
'release_year',
|
|
'developer',
|
|
'publisher',
|
|
'genre',
|
|
'rating',
|
|
'cover_path',
|
|
'thumbnail_path',
|
|
];
|
|
|
|
protected $casts = [
|
|
'rating' => 'decimal:1',
|
|
];
|
|
|
|
protected static function booted(): void
|
|
{
|
|
static::creating(function (Game $game) {
|
|
if (empty($game->slug)) {
|
|
$game->slug = Str::slug($game->title);
|
|
}
|
|
});
|
|
}
|
|
|
|
public function console(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Console::class);
|
|
}
|
|
|
|
public function romFiles(): HasMany
|
|
{
|
|
return $this->hasMany(RomFile::class);
|
|
}
|
|
|
|
public function saveFiles(): HasMany
|
|
{
|
|
return $this->hasMany(SaveFile::class);
|
|
}
|
|
|
|
public function getRouteKeyName(): string
|
|
{
|
|
return 'slug';
|
|
}
|
|
}
|