/** * */ 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(); } }