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:
@@ -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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user