Added quiz new features
This commit is contained in:
28
app/Models/DailyQuest.php
Normal file
28
app/Models/DailyQuest.php
Normal 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');
|
||||
}
|
||||
}
|
||||
@@ -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
35
app/Models/UserQuest.php
Normal 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');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user