예제 #1
0
 public function getEdit($id = null)
 {
     # Get this recipe and eager load its specifics
     $recipe = \App\Recipe::with('specifics')->find($id);
     if (is_null($recipe)) {
         \Session::flash('flash_message', 'Recipe not found.');
         return redirect('\\recipes');
     }
     # Get all the possible menus so we can build the menus dropdown in the view
     $menuModel = new \App\Menu();
     $menus_for_dropdown = $menuModel->getMenusForDropdown();
     # Get all the possible specifics so we can include them with checkboxes in the view
     $specificModel = new \App\Specific();
     $specifics_for_checkbox = $specificModel->getSpecificsForCheckboxes();
     /*
     Create a simple array of just the specific names for spceicifcs associated with this recipe;
     will be used in the view to decide which specifics should be checked off
     */
     $specifics_for_this_recipe = [];
     foreach ($recipe->specifics as $specific) {
         $specific_for_this_recipe[] = $specific->name;
     }
     return view('recipes.edit')->with(['recipe' => $recipe, 'menus_for_dropdown' => $menus_for_dropdown, 'specifics_for_checkbox' => $specifics_for_checkbox, 'specifics_for_this_recipe' => $specifics_for_this_recipe]);
 }
예제 #2
0
 /**
  * Show the form for editing the specified resource.
  *
  * @param  string $slug
  * @return \Illuminate\Http\Response
  */
 public function edit($slug)
 {
     $recipe = Recipe::with('recipeIngredients.ingredient')->where('slug', '=', $slug)->first();
     if (empty($recipe)) {
         abort(404);
     }
     return view('recipes.edit')->with(compact('recipe'));
 }