lots of progress
This commit is contained in:
+74
-3
@@ -5,6 +5,7 @@ namespace App\Models;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class Game extends Model
|
||||
{
|
||||
@@ -34,11 +35,81 @@ class Game extends Model
|
||||
|
||||
public function genres(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Genre::class);
|
||||
return $this->belongsToMany(Genre::class, 'game_genre', 'game_id', 'genre_id');
|
||||
}
|
||||
|
||||
public function platforms(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Platform::class);
|
||||
return $this->belongsToMany(Platform::class, 'game_platform', 'game_id', 'platform_id');
|
||||
}
|
||||
}
|
||||
|
||||
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');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class GameList extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'name',
|
||||
'slug',
|
||||
'description',
|
||||
'is_default'
|
||||
];
|
||||
|
||||
protected static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
static::creating(function ($list) {
|
||||
$list->slug = Str::slug($list->name);
|
||||
});
|
||||
|
||||
static::updating(function ($list) {
|
||||
$list->slug = Str::slug($list->name);
|
||||
});
|
||||
}
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function games(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Game::class)->withTimestamps();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class Rating extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'game_id',
|
||||
'rating',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'rating' => 'integer',
|
||||
];
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function game(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Game::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class Review extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'game_id',
|
||||
'content',
|
||||
'recommended',
|
||||
'rating',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'recommended' => 'boolean',
|
||||
'rating' => 'integer',
|
||||
];
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function game(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Game::class);
|
||||
}
|
||||
}
|
||||
+35
-5
@@ -6,6 +6,7 @@ namespace App\Models;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class User extends Authenticatable
|
||||
{
|
||||
@@ -38,11 +39,40 @@ class User extends Authenticatable
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function casts(): array
|
||||
protected $casts = [
|
||||
'email_verified_at' => 'datetime',
|
||||
'password' => 'hashed',
|
||||
];
|
||||
|
||||
public function reviews(): HasMany
|
||||
{
|
||||
return [
|
||||
'email_verified_at' => 'datetime',
|
||||
'password' => 'hashed',
|
||||
];
|
||||
return $this->hasMany(Review::class);
|
||||
}
|
||||
|
||||
public function ratings(): HasMany
|
||||
{
|
||||
return $this->hasMany(Rating::class);
|
||||
}
|
||||
|
||||
public function lists()
|
||||
{
|
||||
return $this->hasMany(GameList::class);
|
||||
}
|
||||
|
||||
protected static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
static::created(function ($user) {
|
||||
// Create default lists
|
||||
$defaultLists = [
|
||||
['name' => 'Played Games', 'is_default' => true],
|
||||
['name' => 'Want to Play', 'is_default' => true]
|
||||
];
|
||||
|
||||
foreach ($defaultLists as $list) {
|
||||
$user->lists()->create($list);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user