/**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Requests\SessionSetRequest $request)
 {
     $sessionSet = new SessionSet();
     $sessionSet->session_id = $request->session_id;
     $sessionSet->number_of_reps = $request->number_of_reps;
     $sessionSet->weight_lifted = $request->weight_lifted;
     $sessionSet->one_rep_max = $this->calculateOneRepMax($sessionSet->weight_lifted, $sessionSet->number_of_reps);
     $sessionSet->failed = 0;
     $sessionSet->save();
     // refactor this code; create function in ExerciseController to update exercise
     $exercise = Auth::user()->exercises()->findOrFail($sessionSet->session->exercise_id);
     $bestOneRepMax = SessionSet::join('sessions', 'sessions.id', '=', 'session_sets.session_id')->where('sessions.exercise_id', '=', $exercise->id)->max('one_rep_max');
     $exercise->update(['best_one_rep_max' => $bestOneRepMax]);
     return redirect()->action('LogController@showLog');
 }
 /**
  * 
  *
  * 
  */
 public function generateLogFromWK(Request $request)
 {
     $planExercises = PlanExercise::with('planSets')->where('plan_workout_id', '=', $request->input('id'))->get();
     foreach ($planExercises as $planExercise) {
         $session = new Session();
         $session->exercise_id = $planExercise->exercise->id;
         $session->session_date = Carbon::now();
         Auth::user()->sessions()->save($session);
         foreach ($planExercise->planSets as $planSet) {
             $sessionSet = new SessionSet();
             $sessionSet->session_id = $session->id;
             $sessionSet->number_of_reps = $planSet->expected_reps;
             $sessionSet->weight_lifted = $planSet->expected_weight;
             $sessionSet->one_rep_max = $sessionSet->weight_lifted * 36 / (37 - $sessionSet->number_of_reps);
             $sessionSet->failed = 0;
             $sessionSet->save();
             $exercise = Auth::user()->exercises()->findOrFail($sessionSet->session->exercise_id);
             $bestOneRepMax = SessionSet::join('sessions', 'sessions.id', '=', 'session_sets.session_id')->where('sessions.exercise_id', '=', $exercise->id)->max('one_rep_max');
             $exercise->update(['best_one_rep_max' => $bestOneRepMax]);
         }
     }
     return redirect()->action('LogController@showLog');
 }