From e257c28faf1c94dfd46f33d1cec7e38fc3c4248c Mon Sep 17 00:00:00 2001 From: jk Date: Tue, 22 Jun 2021 12:17:10 +0100 Subject: [PATCH] yeasts refactor mkI --- app/Http/Controllers/YeastController.php | 62 ++++++++++++++++-- resources/views/yeasts.blade.php | 83 +----------------------- resources/views/yeasts/create.blade.php | 48 ++++++++++++++ resources/views/yeasts/edit.blade.php | 47 ++++++++++++++ resources/views/yeasts/index.blade.php | 49 ++++++++++++++ routes/web.php | 7 +- 6 files changed, 204 insertions(+), 92 deletions(-) diff --git a/app/Http/Controllers/YeastController.php b/app/Http/Controllers/YeastController.php index 9295973..e8ab40f 100644 --- a/app/Http/Controllers/YeastController.php +++ b/app/Http/Controllers/YeastController.php @@ -15,7 +15,7 @@ class YeastController extends Controller public function index() { $yeasts = Yeast::orderBy('name')->get(); - return view('yeasts')->with('yeasts', $yeasts); + return view('yeasts.index')->with('yeasts', $yeasts); } public function store(Request $request){ @@ -27,7 +27,7 @@ class YeastController extends Controller // create project $yeast = new Yeast; - $lastID = Yeast::orderBy('id','desc')->value('id'); + $lastID = Yeast::orderBy('id','desc')->take(1)->value('id'); $yeast->id = number_format($lastID) + 1; $yeast->name = $request->input('name'); if ($request->input('attenuation')) @@ -39,10 +39,10 @@ class YeastController extends Controller $yeast->flocculation = $request->input('flocculation'); } if ($request->input('profile')) - { - $yeast->profile = '{'.$request->input('profile').'}'; - } - if ($request->input('tolerance')) + { + $yeast->profile = '{'.$request->input('profile').'}'; + } + if ($request->input('tolerance')) { $yeast->tolerance = $request->input('tolerance'); } @@ -52,6 +52,54 @@ class YeastController extends Controller } $yeast->save(); - return redirect('/yeasts')->with('success', 'Yeast Added'); + return redirect('/yeasts')->with('success', 'Yeast Added!'); + } + public function edit($id){ + $grain = Grain::where('id', (int)$id)->first(); + return view('grains.edit')->with('grain', $grain); + } + + public function update(Request $request, $id){ + // validation + $this->validate($request,[ + 'name' => 'required', + ]); + + $yeast = Yeast::where('id', (int)$id)->first(); + $yeast->name = $request->input('name'); + if ($request->input('attenuation')) + { + $yeast->attenuation = $request->input('attenuation'); + } + if ($request->input('flocculation')) + { + $yeast->flocculation = $request->input('flocculation'); + } + if ($request->input('profile')) + { + $yeast->profile = '{'.$request->input('profile').'}'; + } + if ($request->input('tolerance')) + { + $yeast->tolerance = $request->input('tolerance'); + } + if ($request->input('temp_range')) + { + $yeast->temp_range = $request->input('temp_range'); + } + $yeast->save(); + + return redirect('/yeasts')->with('success', 'Yeast Updated!'); + } + public function create() + { + return view('yeasts.create'); + } + public function destroy($id) + { + $yeast = Yeast::find($id); + $yeast->delete(); + + return redirect('/yeasts')->with('success', 'Yeast deleted!'); } } diff --git a/resources/views/yeasts.blade.php b/resources/views/yeasts.blade.php index bae6344..9ede88a 100644 --- a/resources/views/yeasts.blade.php +++ b/resources/views/yeasts.blade.php @@ -1,87 +1,8 @@ @extends('layouts.app') @section('content') -
-
-
-
-@include('inc.navbar') -
Home -> {{ __('Yeast List') }}Go Back
- -
-@if (Auth::user()->isAdmin()) - -
-@endif - - - @include('inc.messages') - - - - - - - - @foreach ($yeasts as $yeast) - - - - - @endforeach - -
NameProfile
{{$yeast->name}} {{str_replace(' ,',',',str_replace('"',' ',str_replace(',',', ',str_replace('}', '', str_replace('{','',$yeast->profile)))))}}
-
-
-
-
-
- -