From 56d623fa9234f7c8015bf15555b327895fc8a1d7 Mon Sep 17 00:00:00 2001 From: jk Date: Tue, 22 Jun 2021 13:57:15 +0100 Subject: [PATCH] hopadditions refactor mkI --- .../Controllers/HopAdditionController.php | 50 +++- app/Http/Controllers/MasheController.php | 2 +- resources/views/adjunct.blade.php | 2 +- resources/views/adjuncts/create.blade.php | 2 +- resources/views/adjuncts/edit.blade.php | 2 +- resources/views/adjuncts/index.blade.php | 2 +- resources/views/beer.blade.php | 6 +- resources/views/beers/create.blade.php | 2 +- resources/views/beers/edit.blade.php | 2 +- resources/views/beers/index.blade.php | 2 +- resources/views/breweries/create.blade.php | 2 +- resources/views/breweries/edit.blade.php | 6 +- resources/views/breweries/index.blade.php | 3 +- resources/views/brewery.blade.php | 4 +- resources/views/edit.blade.php | 231 ------------------ resources/views/grain.blade.php | 2 +- resources/views/grainbill.blade.php | 2 +- resources/views/grainbills/create.blade.php | 2 +- resources/views/grainbills/edit.blade.php | 2 +- resources/views/grainbills/index.blade.php | 2 +- resources/views/grains/create.blade.php | 2 +- resources/views/grains/edit.blade.php | 2 +- resources/views/grains/index.blade.php | 2 +- resources/views/hop.blade.php | 2 +- resources/views/hopadditions.blade.php | 79 +----- resources/views/hopadditions/create.blade.php | 40 +++ resources/views/hopadditions/edit.blade.php | 39 +++ resources/views/hopadditions/index.blade.php | 54 ++++ resources/views/hops/create.blade.php | 2 +- resources/views/hops/edit.blade.php | 2 +- resources/views/hops/index.blade.php | 2 +- resources/views/yeast.blade.php | 2 +- resources/views/yeasts/create.blade.php | 2 +- resources/views/yeasts/edit.blade.php | 2 +- resources/views/yeasts/index.blade.php | 2 +- routes/web.php | 3 +- 36 files changed, 215 insertions(+), 350 deletions(-) delete mode 100644 resources/views/edit.blade.php diff --git a/app/Http/Controllers/HopAdditionController.php b/app/Http/Controllers/HopAdditionController.php index 818da1f..8aab39e 100644 --- a/app/Http/Controllers/HopAdditionController.php +++ b/app/Http/Controllers/HopAdditionController.php @@ -4,6 +4,8 @@ namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Models\Hopaddition; +use App\Models\Hop; +use App\Models\Summarie; class HopAdditionController extends Controller { public function __construct() @@ -14,8 +16,15 @@ class HopAdditionController extends Controller public function index() { - $project = Hopaddition::orderBy('id')->get(); - return view('hopadditions')->with('hopadditions', $project); + $hopadditions = Hopaddition::orderBy('id')->get(); + foreach ($hopadditions as $hopaddition) + { + $beername = Summarie::where('beer_id', $hopaddition->beer_id)->value('name'); + $hopname = Hop::where('id', $hopaddition->hop_id)->value('name'); + $hopaddition['beer'] = $beername; + $hopaddition['hop'] = $hopname; + } + return view('hopadditions.index')->with('hopadditions', $hopadditions); } public function store(Request $request){ @@ -26,11 +35,9 @@ class HopAdditionController extends Controller 'amount' => 'required', 'timing' => 'required', ]); - - // create project $hop = new Hopaddition; - $lastID = Hopaddition::orderBy('id','desc')->value('id'); + $lastID = Hopaddition::orderBy('id','desc')->take(1)->value('id'); $hop->id = number_format($lastID) + 1; $hop->beer_id = $request->input('beer_id'); $hop->hop_id = $request->input('hop_id'); @@ -40,5 +47,38 @@ class HopAdditionController extends Controller return redirect('/hopadditions')->with('success', 'Hop Addition Added'); } + public function edit($id){ + $hopaddition = Hopaddition::where('id', (int)$id)->first(); + return view('hopadditions.edit')->with('hopaddition', $hopaddition); + } + + public function update(Request $request, $id){ + // validation + $this->validate($request,[ + 'beer_id' => 'required', + 'hop_id' => 'required', + 'amount' => 'required', + 'timing' => 'required', + ]); + $hop = Hopaddition::where('id', (int)$id)->first(); + $hop->beer_id = $request->input('beer_id'); + $hop->hop_id = $request->input('hop_id'); + $hop->amount = $request->input('amount'); + $hop->timing = $request->input('timing'); + $hop->save(); + + return redirect('/hopadditions')->with('success', 'Hop Addition Updated!'); + } + public function create() + { + return view('hopadditions.create'); + } + public function destroy($id) + { + $hopaddition = Hopaddition::find($id); + $hopaddition->delete(); + + return redirect('/hopadditions')->with('success', 'Hop Addition deleted!'); + } } diff --git a/app/Http/Controllers/MasheController.php b/app/Http/Controllers/MasheController.php index c2ebb4b..7d4496a 100644 --- a/app/Http/Controllers/MasheController.php +++ b/app/Http/Controllers/MasheController.php @@ -71,7 +71,7 @@ class MasheController extends Controller $mash->boil = $request->input('boil'); $mash->save(); - return redirect('/mashs')->with('success', 'Mash Step Updated!'); + return redirect('/mashes')->with('success', 'Mash Step Updated!'); } public function create() { diff --git a/resources/views/adjunct.blade.php b/resources/views/adjunct.blade.php index 67cfb17..d642645 100644 --- a/resources/views/adjunct.blade.php +++ b/resources/views/adjunct.blade.php @@ -3,7 +3,7 @@ @section('content')
-
+
@include('inc.navbar') diff --git a/resources/views/adjuncts/create.blade.php b/resources/views/adjuncts/create.blade.php index 41633fc..c7fec5c 100644 --- a/resources/views/adjuncts/create.blade.php +++ b/resources/views/adjuncts/create.blade.php @@ -2,7 +2,7 @@ @section('main')
-
+

Add an Adjunct

@if ($errors->any()) diff --git a/resources/views/adjuncts/edit.blade.php b/resources/views/adjuncts/edit.blade.php index 3d5460a..ec3d9a9 100644 --- a/resources/views/adjuncts/edit.blade.php +++ b/resources/views/adjuncts/edit.blade.php @@ -1,6 +1,6 @@ @extends('adjuncts') @section('main')
-
+

Update Adjunct

@if ($errors->any()) diff --git a/resources/views/adjuncts/index.blade.php b/resources/views/adjuncts/index.blade.php index c3b8e7e..d910dd3 100644 --- a/resources/views/adjuncts/index.blade.php +++ b/resources/views/adjuncts/index.blade.php @@ -3,7 +3,7 @@ @section('main')
-
+
@include('inc.navbar')
Home -> {{ __('Adjunct List') }}Go Back
diff --git a/resources/views/beer.blade.php b/resources/views/beer.blade.php index 45c1ef5..6fccbdc 100644 --- a/resources/views/beer.blade.php +++ b/resources/views/beer.blade.php @@ -3,7 +3,7 @@ @section('content')
-
+
@include('inc.navbar')
Home -> Beer List -> {{ __('Beer Sheet') }}Go Back
@@ -55,7 +55,7 @@

Notes

{{$beer->notes}} - @endif + @endif @@ -127,7 +127,7 @@ - + diff --git a/resources/views/beers/create.blade.php b/resources/views/beers/create.blade.php index 82d7b9c..92ed5b3 100644 --- a/resources/views/beers/create.blade.php +++ b/resources/views/beers/create.blade.php @@ -2,7 +2,7 @@ @section('main')
-
+

Add a Beer

@if ($errors->any()) diff --git a/resources/views/beers/edit.blade.php b/resources/views/beers/edit.blade.php index 026c113..9774e45 100644 --- a/resources/views/beers/edit.blade.php +++ b/resources/views/beers/edit.blade.php @@ -1,6 +1,6 @@ @extends('beers') @section('main')
-
+

Update Beer

@if ($errors->any()) diff --git a/resources/views/beers/index.blade.php b/resources/views/beers/index.blade.php index 583c759..7046f72 100644 --- a/resources/views/beers/index.blade.php +++ b/resources/views/beers/index.blade.php @@ -3,7 +3,7 @@ @section('main')
-
+
@include('inc.navbar')
Home -> {{ __('Beer List') }}Go Back
diff --git a/resources/views/breweries/create.blade.php b/resources/views/breweries/create.blade.php index 5176518..154297a 100644 --- a/resources/views/breweries/create.blade.php +++ b/resources/views/breweries/create.blade.php @@ -2,7 +2,7 @@ @section('main')
-
+

Add a brewery

@if ($errors->any()) diff --git a/resources/views/breweries/edit.blade.php b/resources/views/breweries/edit.blade.php index d28ba31..9b6cb97 100644 --- a/resources/views/breweries/edit.blade.php +++ b/resources/views/breweries/edit.blade.php @@ -1,6 +1,6 @@ @extends('breweries') @section('main')
-
+

Update Brewery

@if ($errors->any()) @@ -11,10 +11,10 @@ @endforeach
-
+
@endif
- @method('PATCH') + @method('PATCH') @csrf
diff --git a/resources/views/breweries/index.blade.php b/resources/views/breweries/index.blade.php index 071c1ab..e36ddfd 100644 --- a/resources/views/breweries/index.blade.php +++ b/resources/views/breweries/index.blade.php @@ -4,7 +4,7 @@
-
+
@include('inc.navbar')
Home -> {{ __('Brewery List') }}Go Back
@@ -50,4 +50,3 @@
@endsection - diff --git a/resources/views/brewery.blade.php b/resources/views/brewery.blade.php index f7b89f8..fd4ed67 100644 --- a/resources/views/brewery.blade.php +++ b/resources/views/brewery.blade.php @@ -3,7 +3,7 @@ @section('content')
-
+
@include('inc.navbar')
Home -> Brewery List -> {{__('Brewery Sheet') }}Go Back
@@ -48,7 +48,7 @@ @endforeach

Grain Bill ({{$beer->batch}}L Batch)

Name Temp °CDurationDuration
- +
diff --git a/resources/views/edit.blade.php b/resources/views/edit.blade.php deleted file mode 100644 index 59ebcda..0000000 --- a/resources/views/edit.blade.php +++ /dev/null @@ -1,231 +0,0 @@ -@extends('layouts.app') - -@section('content') -
-
-
-
-
Home -> {{ __('Edit Page') }}Go Back
- -
-
    -
  • -
  • -
  • -
  • -
- - -
-
-
-
-
- - - - - - - - - - - - - - - - -@endsection diff --git a/resources/views/grain.blade.php b/resources/views/grain.blade.php index 26f00ca..d0e574c 100644 --- a/resources/views/grain.blade.php +++ b/resources/views/grain.blade.php @@ -3,7 +3,7 @@ @section('content')
-
+
@include('inc.navbar')
Home -> Grain List -> {{ __('Grain Card') }}Go Back
diff --git a/resources/views/grainbill.blade.php b/resources/views/grainbill.blade.php index b87bcde..9aaa2df 100644 --- a/resources/views/grainbill.blade.php +++ b/resources/views/grainbill.blade.php @@ -3,7 +3,7 @@ @section('content')
-
+
Home -> {{ __('Grain Bills') }}Go Back
diff --git a/resources/views/grainbills/create.blade.php b/resources/views/grainbills/create.blade.php index 46fdac8..ad9bd85 100644 --- a/resources/views/grainbills/create.blade.php +++ b/resources/views/grainbills/create.blade.php @@ -2,7 +2,7 @@ @section('main')
-
+

Add a Grain

@if ($errors->any()) diff --git a/resources/views/grainbills/edit.blade.php b/resources/views/grainbills/edit.blade.php index 9ee10ff..661b786 100644 --- a/resources/views/grainbills/edit.blade.php +++ b/resources/views/grainbills/edit.blade.php @@ -1,6 +1,6 @@ @extends('grainbills') @section('main')
-
+

Update Grain Bill

@if ($errors->any()) diff --git a/resources/views/grainbills/index.blade.php b/resources/views/grainbills/index.blade.php index a32f9b7..f722772 100644 --- a/resources/views/grainbills/index.blade.php +++ b/resources/views/grainbills/index.blade.php @@ -3,7 +3,7 @@ @section('main')
-
+
@include('inc.navbar')
Home -> {{ __('Grain Bills') }}Go Back
diff --git a/resources/views/grains/create.blade.php b/resources/views/grains/create.blade.php index c540747..1fb5d87 100644 --- a/resources/views/grains/create.blade.php +++ b/resources/views/grains/create.blade.php @@ -2,7 +2,7 @@ @section('main')
-
+

Add a Grain

@if ($errors->any()) diff --git a/resources/views/grains/edit.blade.php b/resources/views/grains/edit.blade.php index faaedb8..347fa92 100644 --- a/resources/views/grains/edit.blade.php +++ b/resources/views/grains/edit.blade.php @@ -1,6 +1,6 @@ @extends('grains') @section('main')
-
+

Update Grain

@if ($errors->any()) diff --git a/resources/views/grains/index.blade.php b/resources/views/grains/index.blade.php index e49fb35..92ffc27 100644 --- a/resources/views/grains/index.blade.php +++ b/resources/views/grains/index.blade.php @@ -3,7 +3,7 @@ @section('main')
-
+
@include('inc.navbar')
Home -> {{ __('Grain List') }}Go Back
diff --git a/resources/views/hop.blade.php b/resources/views/hop.blade.php index 7f31899..513670b 100644 --- a/resources/views/hop.blade.php +++ b/resources/views/hop.blade.php @@ -3,7 +3,7 @@ @section('content')
-
+
@include('inc.navbar')
Home -> Hop List -> {{ __('Hop Card') }}Go Back
diff --git a/resources/views/hopadditions.blade.php b/resources/views/hopadditions.blade.php index 7e97832..9ede88a 100644 --- a/resources/views/hopadditions.blade.php +++ b/resources/views/hopadditions.blade.php @@ -1,83 +1,8 @@ @extends('layouts.app') @section('content') -
-
-
-
-@include('inc.navbar') -
Home -> {{ __('Hop Additions') }}Go Back
- -
-@if (Auth::user()->isAdmin()) - -
-@endif - - - @include('inc.messages') - - - - - - - - - - - @foreach ($hopadditions as $hopaddition) - - - - - - - @endforeach - -
Beer IDHop IDAmountTiming
{{$hopaddition->beer_id}} {{$hopaddition->hop_id}} {{$hopaddition->amount}} {{$hopaddition->timing}}
-
-
-
-
-
- -