95 lines
2.0 KiB
PHP
95 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
|
use Illuminate\Notifications\Notifiable;
|
|
use Laravel\Jetstream\HasProfilePhoto;
|
|
use Laravel\Sanctum\HasApiTokens;
|
|
|
|
class User extends Authenticatable
|
|
{
|
|
use HasApiTokens;
|
|
use HasFactory;
|
|
use HasProfilePhoto;
|
|
use Notifiable;
|
|
|
|
protected $fillable = [
|
|
'name',
|
|
'mobile',
|
|
'is_admin',
|
|
'email',
|
|
'password',
|
|
'xp',
|
|
'duels_played',
|
|
'duels_won',
|
|
];
|
|
|
|
protected $hidden = [
|
|
'password',
|
|
'remember_token',
|
|
];
|
|
|
|
protected $casts = [
|
|
'email_verified_at' => 'datetime',
|
|
];
|
|
|
|
protected $appends = [
|
|
'profile_photo_url',
|
|
];
|
|
|
|
public function subscribePlans()
|
|
{
|
|
return $this->hasMany(UserSubscriber::class);
|
|
}
|
|
|
|
public function isAdmin()
|
|
{
|
|
return $this->is_admin;
|
|
}
|
|
|
|
public function isSubscriber()
|
|
{
|
|
return $this->subscribePlans()->where('expired_at', '>', now())->exists();
|
|
}
|
|
|
|
public function subscribePlan()
|
|
{
|
|
return $this->subscribePlans()->where('expired_at', '>', now())->first();
|
|
}
|
|
|
|
public function userSubscribers()
|
|
{
|
|
return $this->hasMany(UserSubscriber::class);
|
|
}
|
|
|
|
public function notifications()
|
|
{
|
|
return $this->belongsToMany(Notification::class, 'notification_user')
|
|
->withPivot('read_at')
|
|
->withTimestamps();
|
|
}
|
|
|
|
// ==========================================
|
|
// --- NEW: Gamification Relationships ---
|
|
// ==========================================
|
|
|
|
/**
|
|
* Get all quest records for the user.
|
|
*/
|
|
public function userQuests()
|
|
{
|
|
return $this->hasMany(UserQuest::class);
|
|
}
|
|
|
|
/**
|
|
* Helper relationship to quickly get ONLY active, unexpired quests.
|
|
*/
|
|
public function activeQuests()
|
|
{
|
|
return $this->hasMany(UserQuest::class)
|
|
->where('expires_at', '>', now());
|
|
}
|
|
}
|