namespace App\Http\Controllers;
+use App\Models\Tournament;
+use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Http\Request;
class TournamentController extends Controller
{
- //
+
+ public function single(Request $request, $id) {
+ $tournament = Tournament::with(
+ 'rounds',
+ 'rounds.results',
+ 'participants',
+ 'participants.user',
+ )->findOrFail($id);
+ $this->authorize('view', $tournament);
+ foreach ($tournament->rounds as $round) {
+ try {
+ $this->authorize('seeResults', $round);
+ } catch (AuthorizationException) {
+ $round->hideResults();
+ }
+ }
+ return $tournament->toJson();
+ }
+
}