public function update($userId, $roundId, UpdateRoundRequest $request) { $teeSet = TeeSet::where('course_id', '=', $request->course)->where('tee_type_id', '=', $request->teeType)->first(); $date = Carbon::createFromDate($request->year, $request->month, $request->day); $round = $this->getRound($roundId, $userId); $round->date = $date->toDateString(); $round->tee_set_id = $teeSet->id; $scores = $round->scores; for ($i = 1; $i <= 18; $i++) { $score = $scores[$i - 1]; $score->strokes = $request->scores[$i]; $score->putts = $request->putts[$i]; $score->gir = null; $score->fairway = null; $hole = Hole::where('course_id', '=', $request->course)->where('number', '=', $i)->first(); $score->hole_id = $hole->id; $score->save(); } $round->save(); return $round; }
public function getHole($courseId, $holeNumber) { return Hole::where('course_id', '=', $courseId)->where('number', '=', $holeNumber)->firstOrFail(); }