コード例 #1
0
 /**
  * Save a match to the provided event
  *
  * @return redirect
  **/
 public function saveMatch(CreateMatchRequest $request, Event $event)
 {
     $match = new Match();
     $match->match_type_id = MatchType::where('identifier', $event->type)->first()->id;
     $match->event_id = $event->id;
     $match->save();
     // if there is a team selected then we're going with teams.
     if ($request->teamBlack) {
         $match->teams()->save(Team::find($request->teamBlack));
         $match->teams()->save(Team::find($request->teamYellow));
     } elseif ($request->playersBlack) {
         $teamBlack = new Team();
         $teamBlack->save();
         $teamYellow = new Team();
         $teamYellow->save();
         foreach ($request->playersBlack as $key => $playerId) {
             $teamBlack->players()->save(Player::find($playerId));
             $teamYellow->players()->save(Player::find($request->playersYellow[$key]));
         }
         $match->teams()->save($teamBlack);
         $match->teams()->save($teamYellow);
     }
     return redirect()->route('dashboard.events.single', $event->id)->with('app-success', 'Match created successfully.');
 }