Added quiz new features

This commit is contained in:
m.razaghi
2026-08-19 12:18:35 +03:30
parent f84ef8c067
commit a6b2a1ba30
11 changed files with 549 additions and 0 deletions

28
app/Models/DailyQuest.php Normal file
View File

@@ -0,0 +1,28 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class DailyQuest extends Model
{
use HasFactory;
protected $fillable = [
'title',
'required_amount',
'reward_xp',
'quest_type',
'is_active',
];
protected $casts = [
'is_active' => 'boolean',
];
public function userQuests()
{
return $this->hasMany(UserQuest::class, 'daily_quest_id');
}
}

View File

@@ -21,6 +21,9 @@ class User extends Authenticatable
'is_admin',
'email',
'password',
'xp',
'duels_played',
'duels_won',
];
protected $hidden = [
@@ -67,4 +70,25 @@ class User extends Authenticatable
->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());
}
}

35
app/Models/UserQuest.php Normal file
View File

@@ -0,0 +1,35 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class UserQuest extends Model
{
use HasFactory;
protected $fillable = [
'user_id',
'daily_quest_id',
'current_progress',
'is_completed',
'expires_at',
];
// Casts ensure Laravel automatically converts these to the right data types
protected $casts = [
'is_completed' => 'boolean',
'expires_at' => 'datetime',
];
public function user()
{
return $this->belongsTo(User::class);
}
public function quest()
{
return $this->belongsTo(DailyQuest::class, 'daily_quest_id');
}
}