From fedaff7abf5937fdd4a2d79d622852b96ed37c2f Mon Sep 17 00:00:00 2001 From: jk Date: Tue, 22 Jun 2021 14:35:40 +0100 Subject: [PATCH] adjunctadditions refactor mkI --- .../Controllers/AdjunctAdditionController.php | 56 ++++++++++++++-- resources/views/adjunctadditions.blade.php | 65 +------------------ .../views/adjunctadditions/create.blade.php | 48 ++++++++++++++ .../views/adjunctadditions/edit.blade.php | 47 ++++++++++++++ .../views/adjunctadditions/index.blade.php | 54 +++++++++++++++ routes/web.php | 3 +- 6 files changed, 203 insertions(+), 70 deletions(-) diff --git a/app/Http/Controllers/AdjunctAdditionController.php b/app/Http/Controllers/AdjunctAdditionController.php index d6ac01d..f112fdd 100644 --- a/app/Http/Controllers/AdjunctAdditionController.php +++ b/app/Http/Controllers/AdjunctAdditionController.php @@ -4,6 +4,8 @@ namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Models\Adjunctaddition; +use App\Models\Adjunct; +use App\Models\Summarie; class AdjunctAdditionController extends Controller { @@ -14,8 +16,17 @@ class AdjunctAdditionController extends Controller public function index() { - $project = Adjunctaddition::get(); - return view('adjunctadditions')->with('adjunctadditions', $project); + $adjunctadditions = Adjunctaddition::get(); + foreach ($adjunctadditions as $adjunctaddition) + { + $beername = Summarie::where('beer_id', $adjunctaddition->beer_id)->value('name'); + $adjunctname = Adjunct::where('id', $adjunctaddition->adjunct_id)->value('name'); + $altname = = Adjunct::where('id', $adjunctaddition->alternative)->value('name'); + $adjunctaddition['beer'] = $beername; + $adjunctaddition['name'] = $adjunctname; + $adjunctaddition['alternativename'] = $altname; + } + return view('adjunctadditions.index')->with('adjunctadditions', $project); } @@ -27,11 +38,9 @@ class AdjunctAdditionController extends Controller 'amount' => 'required', 'timing' => 'required', ]); - - // create project $adjunct = new Adjunctaddition; - $lastID = Adjunctaddition::orderBy('id','desc')->value('id'); + $lastID = Adjunctaddition::orderBy('id','desc')->take(1)->value('id'); $adjunct->id = number_format($lastID) + 1; $adjunct->beer_id = $request->input('beer_id'); $adjunct->adjunct_id = $request->input('adjunct_id'); @@ -44,4 +53,41 @@ class AdjunctAdditionController extends Controller return redirect('/adjunctadditions')->with('success', 'Adjunct Addition Added'); } + public function edit($id){ + $adjunctaddition = Adjunctaddition::where('id', (int)$id)->first(); + return view('adjunctadditions.edit')->with('adjunctaddition', $adjunctaddition); + } + + public function update(Request $request, $id){ + // validation + $this->validate($request,[ + 'beer_id' => 'required', + 'adjunct_id' => 'required', + 'amount' => 'required', + 'timing' => 'required', + ]); + + $adjunct = Adjunctaddition::where('id', (int)$id)->first(); + $adjunct->beer_id = $request->input('beer_id'); + $adjunct->adjunct_id = $request->input('adjunct_id'); + $adjunct->amount = $request->input('amount'); + $adjunct->timing = $request->input('timing'); + $adjunct->alternative = $request->input('alternative'); + $adjunct->notes = $request->input('notes'); + + $adjunct->save(); + + return redirect('/adjunctadditions')->with('success', 'Adjunct Addition Updated!'); + } + public function create() + { + return view('adjunctadditions.create'); + } + public function destroy($id) + { + $adjunctaddition = Adjunctaddition::find($id); + $adjunctaddition->delete(); + + return redirect('/adjunctadditions')->with('success', 'Adjunct Addition deleted!'); + } } diff --git a/resources/views/adjunctadditions.blade.php b/resources/views/adjunctadditions.blade.php index 9fbbaad..9ede88a 100644 --- a/resources/views/adjunctadditions.blade.php +++ b/resources/views/adjunctadditions.blade.php @@ -1,69 +1,8 @@ @extends('layouts.app') @section('content') -
-
-
-
-@include('inc.navbar') -
Home -> {{ __('Adjunct Additions') }}Go Back
- -
-@if (Auth::user()->isAdmin()) - -@endif - - @include('inc.messages') -
-
-
-
-
- - +@endsection diff --git a/resources/views/adjunctadditions/index.blade.php b/resources/views/adjunctadditions/index.blade.php index e69de29..12fdee9 100644 --- a/resources/views/adjunctadditions/index.blade.php +++ b/resources/views/adjunctadditions/index.blade.php @@ -0,0 +1,54 @@ +@extends('adjunctadditions') + +@section('main') +
+
+
+
+@include('inc.navbar') +
Home -> {{ __('Adjunct Additions') }}Go Back
+ +
+@if (Auth::user()->isAdmin()) +Add Adjunct Addition +@endif + + + @include('inc.messages') + + + + + + + + + @if (Auth::user()->isAdmin())@endif + + @foreach ($adjunctadditions as $adjunctaddition) + + + + + + + + @if (Auth::user()->isAdmin()) + + + @endif + + @endforeach + +
AdjunctBeerAmountTimingAlternativeNotesAdmin
{{$adjunctaddition->name}} {{$adjunctaddition->beer}} {{$adjunctaddition->amount}} {{$adjunctaddition->timing}} {{$adjunctaddition->alternativename}} {{$adjunctaddition->notes}} Edit
+ @csrf + @method('DELETE') + +
+
+
+
+
+
+ +@endsection diff --git a/routes/web.php b/routes/web.php index 19ad11b..1b134a7 100644 --- a/routes/web.php +++ b/routes/web.php @@ -32,12 +32,11 @@ Route::resource('grainbills', 'App\Http\Controllers\GrainbillController'); Route::resource('mashes', 'App\Http\Controllers\MasheController'); Route::resource('hopadditions', 'App\Http\Controllers\HopAdditionController'); Route::resource('fermentations', 'App\Http\Controllers\FermentationController'); +Route::resource('adjunctadditions', 'App\Http\Controllers\AdjunctAdditionController'); Route::get('/home', [App\Http\Controllers\SummarieController::class, 'index'])->name('home'); -Route::get('/adjunctadditions', [App\Http\Controllers\AdjunctAdditionController::class, 'index'])->name('adjunctadditions'); Route::get('/brewery/{breweryID}', [App\Http\Controllers\BreweryController::class, 'index'])->name('brewery'); Route::get('/beer/{beerID}', [App\Http\Controllers\BeerController::class, 'index'])->name('beer'); Route::get('/grain/{grainID}', [App\Http\Controllers\GraincardController::class, 'index'])->name('grain'); Route::get('/yeast/{yeastID}', [App\Http\Controllers\YeastcardController::class, 'index'])->name('yeast'); Route::get('/hop/{hopID}', [App\Http\Controllers\HopcardController::class, 'index'])->name('hop'); Route::get('/adjunct/{adjunctID}', [App\Http\Controllers\AdjunctcardController::class, 'index'])->name('adjunct'); -Route::post('/adjunctadditions', [App\Http\Controllers\AdjunctAdditionController::class, 'store'])->name('adjunctadditions.store');