middleware('auth'); } public function index() { $fermentations = Fermentation::get(); foreach ($fermentations as $fermentation) { $beername = Summarie::where('beer_id', $fermentation->beer_id)->value('name'); $yeastname = Yeast::where('id', $fermentation->yeast_id)->value('name'); $fermentation['beer'] = $beername; $fermentation['name'] = $yeastname; } return view('fermentations.index')->with('fermentations', $fermentations); } public function store(Request $request){ // validation $this->validate($request,[ 'beer_id' => 'required', 'yeast_id' => 'required', 'temperature' => 'required', 'duration' => 'required', ]); // create project $yeast = new Fermentation; $lastID = Fermentation::orderBy('id','desc')->take(1)->value('id'); $yeast->id = number_format($lastID) + 1; $yeast->beer_id = $request->input('beer_id'); $yeast->yeast_id = $request->input('yeast_id'); $yeast->temperature = $request->input('temperature'); $yeast->duration = $request->input('duration'); if ($request->input('alternative')) { $yeast->alternative = $request->input('alternative'); } $yeast->save(); return redirect('/fermentations')->with('success', 'Fermentation Step Added'); } public function edit($id){ $fermentation = Fermentation::where('id', (int)$id)->first(); $beers = Summarie::orderBy('name')->get(); $selected_beer = $fermentation->beer_id; $yeasts = Yeast::orderBy('name')->get(); $selected_yeast = $fermentation->yeast_id; $selected_alt = $fermentation->alternative; $data = array('fermentation'=>$fermentation, 'beers'=>$beers, 'yeasts'=>$yeasts, 'selected_beer'=>$selected_beer, 'selected_yeast'=>$selected_yeast, 'selected_alt'=>$selected_alt); return view('fermentations.edit')->with($data); } public function update(Request $request, $id){ // validation $this->validate($request,[ 'beer_id' => 'required', 'yeast_id' => 'required', 'temperature' => 'required', 'duration' => 'required', ]); $yeast = Fermentation::where('id', (int)$id)->first(); $yeast->beer_id = $request->input('beer_id'); $yeast->yeast_id = $request->input('yeast_id'); $yeast->temperature = $request->input('temperature'); $yeast->duration = $request->input('duration'); if ($request->input('alternative')) { $yeast->alternative = $request->input('alternative'); } $yeast->save(); return redirect('/fermentations')->with('success', 'Fermentation Step Updated!'); } public function create() { $beers = Summarie::orderBy('name')->get(); $yeasts = Yeast::orderBy('name')->get(); $data = array('beers'=>$beers, 'yeasts'=>$yeasts); return view('fermentations.create')->with($data); } public function destroy($id) { $fermentation = Fermentation::find($id); $fermentation->delete(); return redirect('/fermentations')->with('success', 'Fermentation Step deleted!'); } }