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)))))}}
-
-
-
-
-
- -