Files
score_and_win/app/Models/Registration.php
T

55 lines
1.1 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Registration extends Model
{
protected $fillable = [
'name',
'email',
'phone',
'country_id',
'status',
'total_score',
];
/*
|---------------------------
| Relationships
|---------------------------
*/
// A student has many game sessions (daily plays)
public function sessions()
{
return $this->hasMany(GameSession::class);
}
// A student has many comments
public function comments()
{
return $this->hasMany(Comment::class);
}
public function country()
{
return $this->belongsTo(\App\Models\Country::class);
}
/*
|---------------------------
| Helper methods
|---------------------------
*/
// Check if student already played today
public function playedToday(): bool
{
return $this->sessions()
->whereDate('play_date', today())
->whereHas('shots', fn($q) => $q->havingRaw('COUNT(*) >= 3'))
->exists();
}
}