Initial GameLog setup

- Laravel 11 + Breeze (dark mode) + Tailwind + Alpine.js
- Migrations: games, genres, platforms, companies, pivots,
  user_games, user_lists, reviews, follows, activities
- Models: Game, Genre, Platform, Company, UserGame, UserList,
  Review, ReviewVote, Activity, User (with gamelog fields)
- IgdbService: OAuth2 token management, search, game fetch,
  popular/new releases, genre filter, cover/screenshot URL helpers
- IGDB credentials in config/services.php (from .env)
This commit is contained in:
Mark
2026-05-29 00:33:00 +03:00
commit 531e9d445a
136 changed files with 16037 additions and 0 deletions
+24
View File
@@ -0,0 +1,24 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class Activity extends Model
{
protected $fillable = ['user_id','type','subject_type','subject_id','data'];
protected $casts = ['data'=>'array'];
public function user(): BelongsTo { return $this->belongsTo(User::class); }
public function subject() { return $this->morphTo(); }
public static function log(int $userId, string $type, mixed $subject = null, array $data = []): self
{
return static::create([
'user_id' => $userId,
'type' => $type,
'subject_type' => $subject ? get_class($subject) : null,
'subject_id' => $subject?->id,
'data' => $data,
]);
}
}
+10
View File
@@ -0,0 +1,10 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Company extends Model
{
//
}
+76
View File
@@ -0,0 +1,76 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Spatie\Sluggable\HasSlug;
use Spatie\Sluggable\SlugOptions;
class Game extends Model
{
use HasSlug;
protected $fillable = [
'igdb_id', 'slug', 'title', 'summary', 'cover_url', 'cover_thumb_url',
'release_date', 'release_year', 'rating_avg', 'rating_count', 'review_count',
'library_count', 'status',
];
protected $casts = [
'release_date' => 'date',
'rating_avg' => 'decimal:2',
];
public function getSlugOptions(): SlugOptions
{
return SlugOptions::create()->generateSlugsFrom('title')->saveSlugsTo('slug');
}
public function getRouteKeyName(): string { return 'slug'; }
public function genres(): BelongsToMany
{
return $this->belongsToMany(Genre::class, 'game_genre');
}
public function platforms(): BelongsToMany
{
return $this->belongsToMany(Platform::class, 'game_platform');
}
public function companies(): BelongsToMany
{
return $this->belongsToMany(Company::class, 'game_company')->withPivot('role');
}
public function screenshots(): HasMany
{
return $this->hasMany(GameScreenshot::class)->orderBy('order');
}
public function userGames(): HasMany
{
return $this->hasMany(UserGame::class);
}
public function reviews(): HasMany
{
return $this->hasMany(Review::class)->latest();
}
public function scopePublished($query)
{
return $query->where('status', 'published');
}
public function recalculateRating(): void
{
$stats = $this->userGames()->whereNotNull('rating')->selectRaw('AVG(rating) as avg, COUNT(*) as cnt')->first();
$this->update([
'rating_avg' => $stats->avg ? round($stats->avg, 2) : null,
'rating_count' => $stats->cnt ?? 0,
]);
}
}
+10
View File
@@ -0,0 +1,10 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class GameScreenshot extends Model
{
//
}
+10
View File
@@ -0,0 +1,10 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Genre extends Model
{
//
}
+10
View File
@@ -0,0 +1,10 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Platform extends Model
{
//
}
+15
View File
@@ -0,0 +1,15 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
class Review extends Model
{
protected $fillable = ['user_id','game_id','rating','body','has_spoilers','helpful_count'];
protected $casts = ['has_spoilers'=>'boolean'];
public function user(): BelongsTo { return $this->belongsTo(User::class); }
public function game(): BelongsTo { return $this->belongsTo(Game::class); }
public function votes(): HasMany { return $this->hasMany(ReviewVote::class); }
}
+10
View File
@@ -0,0 +1,10 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class ReviewVote extends Model
{
//
}
+43
View File
@@ -0,0 +1,43 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
class User extends Authenticatable
{
use HasFactory, Notifiable;
protected $fillable = ['name','username','email','password','avatar','bio','location','website','is_private','is_admin'];
protected $hidden = ['password','remember_token'];
protected $casts = ['email_verified_at'=>'datetime','password'=>'hashed','is_private'=>'boolean','is_admin'=>'boolean'];
public function getRouteKeyName(): string { return 'username'; }
public function library(): HasMany { return $this->hasMany(UserGame::class); }
public function reviews(): HasMany { return $this->hasMany(Review::class); }
public function lists(): HasMany { return $this->hasMany(UserList::class); }
public function activities(): HasMany { return $this->hasMany(Activity::class)->latest(); }
public function following(): BelongsToMany
{
return $this->belongsToMany(User::class, 'follows', 'follower_id', 'following_id')->withTimestamps();
}
public function followers(): BelongsToMany
{
return $this->belongsToMany(User::class, 'follows', 'following_id', 'follower_id')->withTimestamps();
}
public function isFollowing(User $user): bool
{
return $this->following()->where('following_id', $user->id)->exists();
}
public function gameEntry(int $gameId): ?UserGame
{
return $this->library()->where('game_id', $gameId)->first();
}
}
+15
View File
@@ -0,0 +1,15 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class UserGame extends Model
{
protected $fillable = ['user_id','game_id','status','rating','start_date','finish_date','hours_played','notes','is_private'];
protected $casts = ['start_date'=>'date','finish_date'=>'date','is_private'=>'boolean'];
const STATUSES = ['playing','played','want_to_play','on_hold','dropped'];
public function user(): BelongsTo { return $this->belongsTo(User::class); }
public function game(): BelongsTo { return $this->belongsTo(Game::class); }
}
+10
View File
@@ -0,0 +1,10 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class UserList extends Model
{
//
}
+10
View File
@@ -0,0 +1,10 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class UserListGame extends Model
{
//
}