コード例 #1
0
 /**
  *
  */
 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();
     }
 }
コード例 #2
0
 /**
  * @test
  * @return void
  */
 public function it_can_delete_a_recipe()
 {
     $this->logInUser();
     $recipe = new Recipe(['name' => 'echidna']);
     $recipe->user()->associate($this->user);
     $recipe->save();
     $this->seeInDatabase('recipes', ['name' => 'echidna']);
     $response = $this->call('DELETE', '/api/recipes/' . $recipe->id);
     $this->assertEquals(204, $response->getStatusCode());
     $this->missingFromDatabase('recipes', ['name' => 'echidna']);
     $response = $this->call('DELETE', '/api/recipes/' . $recipe->id);
     $this->assertEquals(404, $response->getStatusCode());
 }
コード例 #3
0
 /**
  *
  * @param $name
  * @param bool $ingredients
  * @param bool $steps
  * @return Recipe
  */
 public function insert($name, $ingredients = false, $steps = false)
 {
     $recipe = new Recipe(['name' => $name]);
     $recipe->user()->associate(Auth::user());
     $recipe->save();
     if ($steps) {
         $recipe = $this->insertRecipeMethod($recipe, $steps);
     }
     if ($ingredients) {
         $ingredients = $this->insertFoodAndUnitIfNotExist($ingredients);
         $recipe = $this->insertFoodsIntoRecipe($recipe, $ingredients);
     }
     return $recipe;
 }