2025-04-09 23:03:16 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
2025-04-12 17:18:33 +03:00
|
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
2025-04-09 23:03:16 +03:00
|
|
|
|
|
|
|
|
class Game extends Model
|
|
|
|
|
{
|
|
|
|
|
use HasFactory;
|
|
|
|
|
|
|
|
|
|
protected $fillable = [
|
|
|
|
|
'igdb_id',
|
|
|
|
|
'name',
|
|
|
|
|
'summary',
|
|
|
|
|
'storyline',
|
|
|
|
|
'cover_url',
|
|
|
|
|
'slug',
|
|
|
|
|
'first_release_date',
|
|
|
|
|
'rating',
|
|
|
|
|
'rating_count',
|
|
|
|
|
'category',
|
|
|
|
|
'status',
|
|
|
|
|
'url',
|
|
|
|
|
'version_title',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
protected $casts = [
|
|
|
|
|
'first_release_date' => 'date',
|
|
|
|
|
'rating' => 'float',
|
|
|
|
|
'rating_count' => 'integer',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
public function genres(): BelongsToMany
|
|
|
|
|
{
|
2025-04-12 17:18:33 +03:00
|
|
|
return $this->belongsToMany(Genre::class, 'game_genre', 'game_id', 'genre_id');
|
2025-04-09 23:03:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function platforms(): BelongsToMany
|
|
|
|
|
{
|
2025-04-12 17:18:33 +03:00
|
|
|
return $this->belongsToMany(Platform::class, 'game_platform', 'game_id', 'platform_id');
|
2025-04-09 23:03:16 +03:00
|
|
|
}
|
2025-04-12 17:18:33 +03:00
|
|
|
|
|
|
|
|
public function screenshots(): HasMany
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(Screenshot::class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function videos(): HasMany
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(Video::class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function bundles(): BelongsToMany
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsToMany(Game::class, 'game_bundles', 'game_id', 'bundle_id');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function collections(): BelongsToMany
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsToMany(Game::class, 'game_collections', 'game_id', 'collection_id');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function dlcs(): BelongsToMany
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsToMany(Game::class, 'game_dlcs', 'game_id', 'dlc_id');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function expansions(): BelongsToMany
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsToMany(Game::class, 'game_expansions', 'game_id', 'expansion_id');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function franchises(): BelongsToMany
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsToMany(Game::class, 'game_franchises', 'game_id', 'franchise_id');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function ports(): BelongsToMany
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsToMany(Game::class, 'game_ports', 'game_id', 'port_id');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function remakes(): BelongsToMany
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsToMany(Game::class, 'game_remakes', 'game_id', 'remake_id');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function similar_games(): BelongsToMany
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsToMany(Game::class, 'game_similar', 'game_id', 'similar_game_id');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function reviews(): HasMany
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(Review::class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function ratings()
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(Rating::class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function lists()
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsToMany(GameList::class)->withTimestamps();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function averageRating()
|
|
|
|
|
{
|
|
|
|
|
return $this->ratings()->avg('rating');
|
|
|
|
|
}
|
|
|
|
|
}
|