/** * Show the form for creating a new resource. * * @return Response */ public function create($recipe_id, $type) { $recipe = Recipes::findOrFail($recipe_id); if ($type == 'recipe') { $included_recipes = RecipeItems::where(['recipe_id' => $recipe_id, 'type' => $type])->lists('sub_recipe'); $included_recipes[] = $recipe_id; $select_recipes = $included_recipes ? Recipes::whereNotIn('id', $included_recipes)->lists('title', 'id') : Recipes::lists('title', 'id'); if ($select_recipes) { return view('RecipeItems.create_recipe')->with(array('title' => $this->title, 'recipe' => $recipe, 'recipes' => $select_recipes, 'type' => $type)); } else { Session::flash('flash_message', 'It looks like you have included all possible recipes already.'); return Redirect::action('RecipeItemsController@index', $recipe->id); } } else { $items = ItemUnits::orderBy('default', 'DESC')->get(); $items_units = []; foreach ($items as $item) { $items_units['list'][$item->item()->first()->id][] = ['id' => $item->id, 'title' => $item->unit()->first()->title]; $items_units['php_list'][$item->item()->first()->id][$item->id] = $item->unit()->first()->title; $items_units['factors'][$item->id] = $item->factor; } $select_items = Items::whereNotIn('id', RecipeItems::where(['recipe_id' => $recipe_id, 'type' => $type])->lists('item_id'))->orderBy('title', 'ASC')->lists('title', 'id'); if ($select_items) { return view('RecipeItems.create_item')->with(array('title' => $this->title, 'recipe' => $recipe, 'items' => $select_items, 'items_units' => $items_units, 'type' => $type)); } else { Session::flash('flash_message', 'It looks like you have used all possible products in your recipe.'); return Redirect::action('RecipeItemsController@index', $recipe->id); } } }