/**
  * @test
  * @return void
  */
 public function it_can_delete_an_recipe_tag()
 {
     $this->logInUser();
     $tag = new Tag(['name' => 'echidna', 'for' => 'recipe']);
     $tag->user()->associate($this->user);
     $tag->save();
     $this->seeInDatabase('tags', ['name' => 'echidna']);
     $response = $this->call('DELETE', '/api/recipeTags/' . $tag->id);
     $this->assertEquals(204, $response->getStatusCode());
     $this->missingFromDatabase('tags', ['name' => 'echidna']);
     //        // @TODO Test the 404 for the other methods as well (show, update)
     $response = $this->call('DELETE', '/api/recipeTags/' . $tag->id);
     $this->assertEquals(404, $response->getStatusCode());
 }
 public function run()
 {
     Tag::truncate();
     $users = User::all();
     foreach ($users as $user) {
         Tag::create(['name' => 'main meal', 'for' => 'recipe', 'user_id' => $user->id]);
         Tag::create(['name' => 'soup', 'for' => 'recipe', 'user_id' => $user->id]);
         Tag::create(['name' => 'salad', 'for' => 'recipe', 'user_id' => $user->id]);
         Tag::create(['name' => 'dessert', 'for' => 'recipe', 'user_id' => $user->id]);
         Tag::create(['name' => 'fruit salad', 'for' => 'recipe', 'user_id' => $user->id]);
         Tag::create(['name' => 'pushups', 'for' => 'exercise', 'user_id' => $user->id]);
         Tag::create(['name' => 'pullups', 'for' => 'exercise', 'user_id' => $user->id]);
     }
 }
 /**
  *
  */
 private function createRecipes()
 {
     foreach (Config::get('recipes') as $tempRecipe) {
         $recipe = new Recipe(['name' => $tempRecipe['name']]);
         $recipe->user()->associate($this->user);
         $recipe->save();
         foreach ($tempRecipe['ingredients'] as $ingredient) {
             $food = Food::where('user_id', $this->user->id)->where('name', $ingredient['food'])->first();
             $recipe->foods()->attach([$food->id => ['unit_id' => Unit::where('user_id', $this->user->id)->where('name', $ingredient['unit'])->first()->id, 'quantity' => $ingredient['quantity'], 'description' => $ingredient['description']]]);
         }
         foreach ($tempRecipe['tags'] as $tempTag) {
             $tag = Tag::where('user_id', $this->user->id)->where('name', $tempTag)->first();
             $recipe->tags()->attach([$tag->id => ['taggable_type' => 'recipe']]);
         }
         $recipe->save();
     }
 }
 /**
  *
  * @return mixed
  */
 public function getExerciseTags()
 {
     $tags = Tag::forCurrentUser()->where('for', 'exercise')->orderBy('name', 'asc')->get();
     return transform(createCollection($tags, new TagTransformer()))['data'];
 }
 /**
  *
  * @param Tag $tag
  * @return \Illuminate\Http\Response
  * @throws \Exception
  */
 public function destroy(Tag $tag)
 {
     $tag->delete();
     return $this->responseNoContent();
 }
 /**
  *
  * @return mixed
  */
 public function getRecipeTags()
 {
     return Tag::forCurrentUser()->where('for', 'recipe')->orderBy('name', 'asc')->get();
 }
 /**
  * Define your route model bindings, pattern filters, etc.
  *
  * @param  \Illuminate\Routing\Router  $router
  * @return void
  */
 public function boot(Router $router)
 {
     parent::boot($router);
     Route::bind('exercises', function ($id) {
         return Exercise::forCurrentUser()->findOrFail($id);
     });
     Route::bind('exerciseEntries', function ($id) {
         return ExerciseEntry::forCurrentUser()->findOrFail($id);
     });
     Route::bind('menuEntries', function ($id) {
         return MenuEntry::forCurrentUser()->findOrFail($id);
     });
     Route::bind('exerciseSeries', function ($id) {
         return ExerciseSeries::forCurrentUser()->findOrFail($id);
     });
     Route::bind('foods', function ($id) {
         return Food::forCurrentUser()->findOrFail($id);
     });
     Route::bind('recipes', function ($id) {
         return Recipe::forCurrentUser()->findOrFail($id);
     });
     Route::bind('exerciseTags', function ($id) {
         return Tag::forCurrentUser()->where('for', 'exercise')->findOrFail($id);
     });
     Route::bind('recipeTags', function ($id) {
         return Tag::forCurrentUser()->where('for', 'recipe')->findOrFail($id);
     });
     Route::bind('foodUnits', function ($id) {
         return Unit::forCurrentUser()->where('for', 'food')->findOrFail($id);
     });
     Route::bind('exerciseUnits', function ($id) {
         return Unit::forCurrentUser()->where('for', 'exercise')->findOrFail($id);
     });
     Route::bind('timers', function ($id) {
         return Timer::forCurrentUser()->findOrFail($id);
     });
     Route::bind('activities', function ($id) {
         return Activity::forCurrentUser()->findOrFail($id);
     });
     Route::bind('weights', function ($idOrDate) {
         if (strrpos($idOrDate, '-')) {
             //parameter is the date of the entry
             $weight = Weight::forCurrentUser()->where('date', $idOrDate)->first();
         } else {
             //parameter is the id of the entry
             $weight = Weight::forCurrentUser()->findOrFail($idOrDate);
         }
         return $weight;
     });
     /**
      * $parameter is either the id or the date
      */
     Route::bind('journal', function ($parameter) {
         /**
          * @VP:
          * Is there a better way to check if the $parameter is an
          * id or a date? When I tried using Carbon to create an object from
          * the parameter, it threw an exception when the $parameter was the id,
          * whereas I just wanted a boolean.
          */
         if (strrpos($parameter, '-')) {
             //$parameter is the date of the entry
             $journal = Journal::forCurrentUser()->where('date', $parameter)->first();
         } else {
             //$parameter is the id of the entry
             $journal = Journal::forCurrentUser()->findOrFail($parameter);
         }
         return $journal;
     });
 }