diff --git a/app/Http/Controllers/HopController.php b/app/Http/Controllers/HopController.php index 24152ff..061ee47 100644 --- a/app/Http/Controllers/HopController.php +++ b/app/Http/Controllers/HopController.php @@ -16,7 +16,7 @@ class HopController extends Controller public function index() { $project = Hop::orderBy('name')->get(); - return view('hops')->with('hops', $project); + return view('hops.index')->with('hops', $project); } public function store(Request $request){ @@ -28,7 +28,7 @@ class HopController extends Controller // create project $hop = new hop; - $lastID = Hop::orderBy('id','desc')->value('id'); + $lastID = Hop::orderBy('id','desc')->take(1)->value('id'); $hop->id = number_format($lastID) + 1; $hop->name = $request->input('name'); if ($request->input('alpha_acid')) @@ -71,9 +71,71 @@ class HopController extends Controller } $hop->save(); - return redirect('/hops')->with('success', 'Hop Added'); + return redirect('/hops')->with('success', 'Hop Added!'); } + public function edit($id){ + $hop = Hop::where('id', (int)$id)->first(); + return view('hops.edit')->with('hop', $hop); + } + public function update(Request $request, $id){ + // validation + $this->validate($request,[ + 'name' => 'required', + ]); + $hop = Hop::where('id', (int)$id)->first(); + $hop->name = $request->input('name'); + if ($request->input('alpha_acid')) + { + $hop->alpha_acid = $request->input('alpha_acid'); + } + $hop->bitter = $request->input('bitter'); + $hop->aroma = $request->input('aroma'); + if ($request->input('beta_acid')) + { + $hop->beta_acid = $request->input('beta_acid'); + } + if ($request->input('myrcene')) + { + $hop->myrcene = $request->input('myrcene'); + } + if ($request->input('profile')) + { + $hop->profile = '{'.$request->input('profile').'}'; + } + if ($request->input('humulene')) + { + $hop->humulene = $request->input('humulene'); + } + if ($request->input('total_oil')) + { + $hop->total_oil = $request->input('total_oil'); + } + if ($request->input('cohumulone')) + { + $hop->cohumulone = $request->input('cohumulone'); + } + if ($request->input('farnesene')) + { + $hop->farnesene = $request->input('farnesene'); + } + if ($request->input('caryophyllene')) + { + $hop->caryophyllene = $request->input('caryophyllene'); + } + $hop->save(); + return redirect('/hops')->with('success', 'Hop Updated!'); + } + public function create() + { + return view('hops.create'); + } + public function destroy($id) + { + $hop = Hop::find($id); + $hop->delete(); + return redirect('/hops')->with('success', 'Hop deleted!'); + } }