public function start($id) { $tournament = Tournament::find($id); $participants = $tournament->participants; if ($tournament->started == false) { // $registrations =$tournament->registrations()->get(); // echo $registrations[0]->user()->get(); // Von der Registrierung zum User $registrations = $tournament->registrations()->get(); for ($i = 0; $i <= $participants / 2; $i = $i + 2) { echo "test" . $i; $player1 = $registrations[$i]->user()->get(); $player2 = $registrations[$i + 1]->user()->get(); $post = new Result(); $post->user1()->associate($player1[0]); $post->user2()->associate($player2[0]); $post->tournament()->associate($tournament); $post->round = 0; $post->save(); } $tournament->started = 1; $tournament->round = 0; // $tournament->round++; $tournament->save(); } else { $tournament_already_started_message = "Tournament already started"; } // echo count($registrations); return view('results.index', array("tournament_already_started_message" => $tournament_already_started_message, "started" => $tournament->started, 'tournament' => $tournament)); }