/**
  *
  * @param Request $request
  * @return Response
  */
 public function store(Request $request)
 {
     $exercise = new Exercise($request->only('name', 'description', 'step_number', 'default_quantity', 'target', 'priority', 'stretch', 'frequency'));
     $exercise->user()->associate(Auth::user());
     $exercise->program()->associate(ExerciseProgram::find($request->get('program_id')));
     $exercise->series()->associate(Series::find($request->get('series_id')));
     $exercise->defaultUnit()->associate(Unit::find($request->get('default_unit_id')));
     $exercise->save();
     $exercise = $this->transform($this->createItem($exercise, new ExerciseTransformer()))['data'];
     return response($exercise, Response::HTTP_CREATED);
 }
 /**
  *
  * @param $exercises
  * @param Unit $unit
  * @param Series $series
  */
 private function insertExercisesInSeries($exercises, Unit $unit, Series $series)
 {
     $index = 0;
     //        $series_ids = Series::where('user_id', $this->user->id)->lists('id')->all();
     foreach ($exercises as $exercise) {
         $index++;
         $stretch = isset($exercise['stretch']) ? 1 : 0;
         $temp = new Exercise(['name' => $exercise['name'], 'description' => $exercise['description'], 'default_quantity' => $exercise['defaultQuantity'], 'step_number' => $index, 'target' => '3 * 10', 'priority' => $exercise['priority'], 'stretch' => $stretch]);
         if (isset($exercise['frequency'])) {
             $temp['frequency'] = $exercise['frequency'];
         }
         $temp->user()->associate($this->user);
         $temp->defaultUnit()->associate($unit);
         $temp->program()->associate(ExerciseProgram::first());
         $temp->series()->associate($series);
         $temp->save();
     }
 }
 /**
  * @test
  * @return void
  */
 public function it_can_delete_an_exercise()
 {
     $this->logInUser();
     $exercise = new Exercise(['name' => 'echidna']);
     $exercise->user()->associate($this->user);
     $exercise->save();
     $this->seeInDatabase('exercises', ['name' => 'echidna']);
     $response = $this->call('DELETE', '/api/exercises/' . $exercise->id);
     $this->assertEquals(204, $response->getStatusCode());
     $this->missingFromDatabase('exercises', ['name' => 'echidna']);
     $response = $this->call('DELETE', '/api/units/0');
     $this->assertEquals(404, $response->getStatusCode());
 }