public function store($userId, RoundRequest $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 = new Round(); $round->date = $date->toDateString(); $round->user_id = $userId; $round->tee_set_id = $teeSet->id; $scores = []; for ($i = 1; $i <= 18; $i++) { $score = new Score(); $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; $scores[$i] = $score; } $round->save(); $round->scores()->saveMany($scores); return $round; }