I have a Round model for a Laravel PHP game. Each round has a start time (DATETIME) and duration in minutes (INT):
id | game_id | duration | start_time 1 | 3 | 40 | 2022-06-22 19:29:26 2 | 3 | 20 | 2022-06-24 00:02:55 3 | 1 | 10 | 2022-06-25 10:56:05
A game will have multiple rounds. If start_time uration > Carbon::now()
, one round ends
Now I can't seem to figure out how to retrieve all turns from a game that is still in progress
I thought of something similar, but apparently that doesn't work because I can't put the "duration" column into the subMinutes function
return $game->whereHas('rounds', function ($query) { $query->where('start_time', '>', Carbon::now()->subMinutes(duration)); })->first();
You are looking for this in SQL:
or equivalent, in Eloquent: