public function update(Request $request, $id) { $this->validate($request, ['description' => 'required', 'type_id' => 'required']); $ingredient = Ingredient::find($id); $ingredient->fill($request->all()); $ingredient->save(); return Redirect::to('ingredients'); }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $ingredientsupplyorder = new IngredientSupplyOrder(); $ingredientsupplyorder->supplyorder_id = $request->supplyorder_id; $ingredientsupplyorder->ingredient_id = $request->Ingredient; $ingredientsupplyorder->quantity = $request->Quantity; $ingredientsupplyorder->save(); $ingredient = Ingredient::find($ingredientsupplyorder->ingredient_id); Activity::log('Added ' . $ingredient->name . ' to the supply order.'); return Redirect::back()->with('status', 'Supply order updated!'); }
public function update(Request $request) { if (!$this->isUnique($request->name)) { return Response::json("This ingredient already exists", 400); exit; } $recipe = Ingredient::find($request->id); $ingredient->name = $request->name; $ingredient->quantity = $request->quantity; $ingredient->measure = $request->measure; $ingredient->save(); echo json_encode(true); exit; }
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { $ingredient = Ingredient::find($id); $ingredient->delete(); return redirect()->route('ingredient.index'); }
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { $ingredient = Ingredient::find($id); Activity::log('Deleted the ' . $ingredient->name . ' ingredient from the system'); $ingredient->delete(); return Redirect::back()->with('status', 'Ingredient removed!'); }
public function showRecipes($id = null) { $ingredient = \App\Ingredient::find($id); $recipes = $ingredient->recipes()->get(); return view('show')->with('recipes', $recipes); }
/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $id) { $id = $request->id; $productionSchedule = Batch::find($id); $productionSchedule->product_id = $request->Product; $productionSchedule->batches = $request->Batches; $productionSchedule->proddate = $request->Date; $productionSchedule->status_id = $request->Status; $productionSchedule->save(); if ($productionSchedule->status_id == 3) { $product = Product::find($productionSchedule->product_id); $addInventory = $productionSchedule->batches * $product->units_per_batch; $product->inventory = $product->inventory + $addInventory; $product->save(); // for each ingredient in the recipe subtract the units required to make the batch $currentIngredientQuantity = $product->ingredient()->get(); $batches = $productionSchedule->batches; foreach ($currentIngredientQuantity as $i) { $ingredient = Ingredient::find($i->id); $multipleIngredientBatch = $batches * $i->pivot->quantity; $ingredient->quantity = $ingredient->quantity - $multipleIngredientBatch; $ingredient->save(); } Activity::log('Completed ' . $productionSchedule->batches . ' batches of ' . $productionSchedule->product->name . '.'); } else { Activity::log('Updated production schedule #' . $productionSchedule->id . '.'); } $request->session()->flash('status', 'Production schedule was successfully updated.'); return Redirect::action('ProductionController@index'); }