/**
  * Delete the existing method before adding the updated method
  * Todo: fix this after refactor
  * @param Request $request
  * @return array
  */
 public function updateRecipeMethod(Request $request)
 {
     $recipe = Recipe::find($request->get('recipe_id'));
     $steps = $request->get('steps');
     RecipeMethod::deleteRecipeMethod($recipe);
     RecipeMethod::insertRecipeMethod($recipe, $steps);
     return Recipe::getRecipeInfo($recipe);
 }
Ejemplo n.º 2
0
 /**
  * Attach recipe for the last entry if the date is today
  * @param $date
  * @param Entry $entry
  * @param $index
  */
 private function attachRecipe($date, Entry $entry, $index)
 {
     if ($date === Carbon::today()->format('Y-m-d') && $index === 1) {
         $recipe_ids = Recipe::where('user_id', $this->user->id)->lists('id')->all();
         if ($recipe_ids) {
             $entry->recipe()->associate(Recipe::find($recipe_ids[0]));
         }
     }
 }
 /**
  * Entry can be either just a food, or part of a recipe.
  * When part of a recipe, the store method inserts just one food at a time,
  * so that the store method is RESTful.
  * So lots of ajax requests will be made to insert
  * all the entries for a whole recipe.
  * POST /api/menuEntries
  * @param Request $request
  * @return Response
  */
 public function store(Request $request)
 {
     $entry = new Entry($request->only(['date', 'quantity']));
     $entry->user()->associate(Auth::user());
     $entry->food()->associate(Food::find($request->get('food_id')));
     if ($request->get('recipe_id')) {
         $entry->recipe()->associate(Recipe::find($request->get('recipe_id')));
     }
     $entry->unit()->associate(Unit::find($request->get('unit_id')));
     $entry->save();
     $entry = $this->transform($this->createItem($entry, new MenuEntryTransformer()))['data'];
     return response($entry, Response::HTTP_CREATED);
 }