I need to select a particular users weekly top score. I am using Carbon and I forced Carbon startofWeek to SUNDAY and endOfWeek to SATURDAY.
Here is my DB data
id user_id score created_at updated_at
43 33 88 2020-02-23 00:00:00 NULL
44 33 15 2020-02-24 00:00:00 NULL
45 33 42 2020-02-24 00:00:00 NULL
46 33 86 2020-02-25 00:00:00 NULL
47 33 100 2020-02-04 00:00:00 NULL
Here is my code
$week = GameScore::select(max('score')
->where('created_at', '>=', Carbon::now()->startOfWeek(Carbon::SUNDAY))
->where('created_at', '<=', Carbon::now()->endOfWeek(Carbon::SATURDAY))
->where('user_id', $user->id)
->get();
According to my data I need to get score 88 as result , because this score is obtained on 23rd Feb Sunday which is this weeks starting and till today all other scores are not greater than this.