Users UserChallenges(user_id,challenge_id) Challenges(start,end)
I want to get all UserChallenges for a user within a given timerange:
$challengeIds = Challenge::where('start', '>=', $timestamp)
->where('end', '<=', $timestamp)->pluck('id');
UserChallenge::where('user_id', $userId)->whereIn('id', $challengeIds)->get();
I know that I could do it in one query using joins, but I would prefer a more eloquent like way using the relations that I have setup in the models. Is this somehow possible?