generated from theradcoza/Laravel-Docker-Dev-Template
Add leaderboard route with participants, and configure Shell brand colors in Tailwind
This commit is contained in:
57
src/app/Models/Participant.php
Normal file
57
src/app/Models/Participant.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Participant extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'car_number',
|
||||
'time_ms',
|
||||
'status',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'car_number' => 'integer',
|
||||
'time_ms' => 'integer',
|
||||
];
|
||||
|
||||
/**
|
||||
* Format time_ms as mm:ss.ms (e.g., 01:23.456)
|
||||
*/
|
||||
public function getFormattedTimeAttribute(): ?string
|
||||
{
|
||||
if ($this->time_ms === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$totalMs = $this->time_ms;
|
||||
$minutes = floor($totalMs / 60000);
|
||||
$seconds = floor(($totalMs % 60000) / 1000);
|
||||
$milliseconds = $totalMs % 1000;
|
||||
|
||||
return sprintf('%02d:%02d.%03d', $minutes, $seconds, $milliseconds);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope to get ranked participants (fastest first, null times last)
|
||||
*/
|
||||
public function scopeRanked($query)
|
||||
{
|
||||
return $query->orderByRaw('CASE WHEN time_ms IS NULL THEN 1 ELSE 0 END')
|
||||
->orderBy('time_ms', 'asc');
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope to get only completed participants
|
||||
*/
|
||||
public function scopeCompleted($query)
|
||||
{
|
||||
return $query->where('status', 'completed');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user