sort()->first(); $game = $activity?->games()->show() ->whereDate('game_at', now()) ->where('game_at', '>', now()) ->where('state', 1) ->orderBy('game_at', 'asc')->first(); //若已经没有最新的活动了, 则拿取当天最后一个 if(!$game){ $game = $activity?->games()->show() ->whereDate('game_at', now()) ->orderBy('game_at', 'desc')->first(); } if($game){ $game->load(['logs'=> function($q){ $q->where('user_id', auth('api')->user()?->id ?? 0); }]); return ActivityGameResource::make($game); } return $this->success(); } }