/** * Show the form for editing the specified resource. * * @param int $id * @return Response */ public function edit($id) { $waste = Wastes::findOrFail($id); $currentPeriodId = Helper::defaultPeriodId(); $periods = StockPeriods::all(); $period_list = array(); foreach ($periods as $period) { $period_list[$period->id] = 'Stock #' . $period->number . ' (' . $period->date_from . ' - ' . ($period->id == $currentPeriodId ? 'NOW' : $period->date_to) . ')'; } if (Input::has('stock_period')) { $currentPeriodId = Input::get('stock_period'); } $select_recipes = Recipes::orderBy('title', 'ASC')->lists('title', 'id'); $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::orderBy('title', 'ASC')->lists('title', 'id'); $select_menus = Menu::orderBy('title', 'ASC')->lists('title', 'id'); $select_reasons = WasteReasons::orderBy('reason', 'ASC')->lists('reason', 'id'); return view('Wastes.edit')->with(array('title' => $this->title, 'recipes' => $select_recipes, 'items' => $select_items, 'items_units' => $items_units, 'menus' => $select_menus, 'period' => $currentPeriodId, 'stocks_list' => $period_list, 'reasons' => $select_reasons, 'waste' => $waste)); }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { $reason = WasteReasons::findOrFail($id); $reason->delete(); Helper::add($id, 'deleted waste reason (ID ' . $id . ')'); Session::flash('flash_message', $this->title . ' successfully deleted!'); return Redirect::action('WasteReasonsController@index'); }