diff --git a/app/Http/Controllers/BrewerieController.php b/app/Http/Controllers/BrewerieController.php index 15e82e6..e697a65 100644 --- a/app/Http/Controllers/BrewerieController.php +++ b/app/Http/Controllers/BrewerieController.php @@ -27,7 +27,7 @@ class BrewerieController extends Controller // create project $brewerie = new Brewerie; - $lastID = Brewerie::orderBy('id','desc')->value('id'); + $lastID = Brewerie::orderBy('id','desc')->take(1)->value('id'); $brewerie->id = number_format($lastID) + 1; $brewerie->name = $request->input('name'); if ($request->input('place')) @@ -44,8 +44,8 @@ class BrewerieController extends Controller } public function edit($id){ - $brewery = Brewerie::where('id', (int)$id)->first(); - return view('breweries.edit')->with('brewery', $brewery); + $brewery = Brewerie::where('id', (int)$id)->first(); + return view('breweries.edit')->with('brewery', $brewery); } public function update(Request $request, $id) @@ -77,4 +77,3 @@ class BrewerieController extends Controller } } - diff --git a/app/Http/Controllers/GrainController.php b/app/Http/Controllers/GrainController.php index aa6669c..a08360e 100644 --- a/app/Http/Controllers/GrainController.php +++ b/app/Http/Controllers/GrainController.php @@ -16,7 +16,7 @@ class GrainController extends Controller public function index() { $grains = Grain::orderBy('name')->get(); - return view('grains')->with('grains', $grains); + return view('grains.index')->with('grains', $grains); } public function store(Request $request){ @@ -25,45 +25,101 @@ class GrainController extends Controller 'name' => 'required', ]); - // create project $grain = new Grain; - $lastID = Grain::orderBy('id','desc')->value('id'); - $grain->id = number_format($lastID) + 1; + $lastID = Grain::orderBy('id','desc')->take(1)->value('id'); + $grain->id = number_format($lastID) + 1; $grain->name = $request->input('name'); if ($request->input('flavour')) - { - $grain->flavour = $request->input('flavour'); - } + { + $grain->flavour = $request->input('flavour'); + } if ($request->input('lintner')) { - $grain->lintner = $request->input('lintner'); - } + $grain->lintner = $request->input('lintner'); + } if ($request->input('winkol')) { - $grain->winkol = $request->input('winkol'); - } + $grain->winkol = $request->input('winkol'); + } if ($request->input('lovibond')) { - $grain->lovibond = $request->input('lovibond'); - } + $grain->lovibond = $request->input('lovibond'); + } if ($request->input('colour')) { - $grain->colour = $request->input('colour'); - } + $grain->colour = $request->input('colour'); + } if ($request->input('alternative')) { - $altArr = array_map('intval',explode(',',$request->input('alternative'))); - $grain->alternative = $altArr; - } + $altArr = array_map('intval',explode(',',$request->input('alternative'))); + $grain->alternative = $altArr; + } if ($request->input('ebc')) { - $grain->ebc = $request->input('ebc'); + $grain->ebc = $request->input('ebc'); } - $grain->save(); + $grain->save(); return redirect('/grains')->with('success', 'Grain Added'); } + public function edit($id){ + $brewery = Brewerie::where('id', (int)$id)->first(); + return view('breweries.edit')->with('brewery', $brewery); + } + + public function update(Request $request, $id){ + // validation + $this->validate($request,[ + 'name' => 'required', + ]); + + $grain = Grain::where('id', $id)->first(); + $grain->name = $request->input('name'); + if ($request->input('flavour')) + { + $grain->flavour = $request->input('flavour'); + } + if ($request->input('lintner')) + { + $grain->lintner = $request->input('lintner'); + } + if ($request->input('winkol')) + { + $grain->winkol = $request->input('winkol'); + } + if ($request->input('lovibond')) + { + $grain->lovibond = $request->input('lovibond'); + } + if ($request->input('colour')) + { + $grain->colour = $request->input('colour'); + } + if ($request->input('alternative')) + { + $altArr = array_map('intval',explode(',',$request->input('alternative'))); + $grain->alternative = $altArr; + } + if ($request->input('ebc')) + { + $grain->ebc = $request->input('ebc'); + } + $grain->save(); + + return redirect('/grains')->with('success', 'Grain Updated!'); + } + public function create() + { + return view('grains.create'); + } + public function destroy($id) + { + $grain = Grain::find($id); + $grain->delete(); + + return redirect('/grains')->with('success', 'Grain deleted!'); + } } diff --git a/resources/views/beers/create.blade.php b/resources/views/beers/create.blade.php index 1a4e2ff..82d7b9c 100644 --- a/resources/views/beers/create.blade.php +++ b/resources/views/beers/create.blade.php @@ -28,7 +28,7 @@ -
+
diff --git a/resources/views/grains/create.blade.php b/resources/views/grains/create.blade.php index e69de29..58114ed 100644 --- a/resources/views/grains/create.blade.php +++ b/resources/views/grains/create.blade.php @@ -0,0 +1,56 @@ +@extends('grains') + +@section('main') +
+
+

Add a Grain

+
+ @if ($errors->any()) +
+
    + @foreach ($errors->all() as $error) +
  • {{ $error }}
  • + @endforeach +
+

+ @endif +
+ @csrf +
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+ +
+
+
+
+@endsection diff --git a/resources/views/grains/edit.blade.php b/resources/views/grains/edit.blade.php index e69de29..caff0c0 100644 --- a/resources/views/grains/edit.blade.php +++ b/resources/views/grains/edit.blade.php @@ -0,0 +1,55 @@ +@extends('grains') +@section('main')
+
+

Update Grain

+ + @if ($errors->any()) +
+
    + @foreach ($errors->all() as $error) +
  • {{ $error }}
  • + @endforeach +
+
+
+ @endif +
+ @method('PATCH') + @csrf +
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + alternative)))))}}"/> +
+ +
+
+
+@endsection diff --git a/resources/views/grains/index.blade.php b/resources/views/grains/index.blade.php index e69de29..69b9f28 100644 --- a/resources/views/grains/index.blade.php +++ b/resources/views/grains/index.blade.php @@ -0,0 +1,40 @@ +@extends('grains') + +@section('main') +
+
+
+
+@include('inc.navbar') +
Home -> {{ __('Grain List') }}Go Back
+ +
+@if (Auth::user()->isAdmin()) + Add Grain +
+@endif + + + @include('inc.messages') + + + @foreach ($grains as $grain) + + + @if (Auth::user()->isAdmin()) + + + @endif + + @endforeach + +
{{$grain->name}} Edit
+ @csrf + @method('DELETE') + +
+
+
+
+
+
diff --git a/routes/web.php b/routes/web.php index 2e4e647..b47ed7f 100644 --- a/routes/web.php +++ b/routes/web.php @@ -24,12 +24,12 @@ Route::any('/register', function() { Route::resource('breweries', 'App\Http\Controllers\BrewerieController'); Route::resource('beers', 'App\Http\Controllers\SummarieController'); +Route::resource('grains', 'App\Http\Controllers\GrainController'); Route::get('/home', [App\Http\Controllers\SummarieController::class, 'index'])->name('home'); Route::get('/adjuncts', [App\Http\Controllers\AdjunctController::class, 'index'])->name('adjuncts'); -Route::get('/grains', [App\Http\Controllers\GrainController::class, 'index'])->name('grains'); +//Route::get('/grains', [App\Http\Controllers\GrainController::class, 'index'])->name('grains'); Route::get('/hops', [App\Http\Controllers\HopController::class, 'index'])->name('hops'); Route::get('/yeasts', [App\Http\Controllers\YeastController::class, 'index'])->name('yeasts'); -//Route::get('/beers', [App\Http\Controllers\SummarieController::class, 'index'])->name('beers'); Route::get('/fermentations', [App\Http\Controllers\FermentationController::class, 'index'])->name('fermentations'); Route::get('/grainbills', [App\Http\Controllers\GrainbillController::class, 'index'])->name('grainbills'); Route::get('/mashes', [App\Http\Controllers\MasheController::class, 'index'])->name('mashes'); @@ -41,11 +41,10 @@ Route::get('/grain/{grainID}', [App\Http\Controllers\GraincardController::class, 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('/grains', [App\Http\Controllers\GrainController::class, 'store'])->name('grains.store'); +//Route::post('/grains', [App\Http\Controllers\GrainController::class, 'store'])->name('grains.store'); Route::post('/hops', [App\Http\Controllers\HopController::class, 'store'])->name('hops.store'); Route::post('/yeasts', [App\Http\Controllers\YeastController::class, 'store'])->name('yeasts.store'); Route::post('/adjuncts', [App\Http\Controllers\AdjunctController::class, 'store'])->name('adjuncts.store'); -//Route::post('/beers', [App\Http\Controllers\SummarieController::class, 'store'])->name('beers.store'); Route::post('/grainbills', [App\Http\Controllers\GrainbillController::class, 'store'])->name('grainbills.store'); Route::post('/mashes', [App\Http\Controllers\MasheController::class, 'store'])->name('mash.store'); Route::post('/hopadditions', [App\Http\Controllers\HopAdditionController::class, 'store'])->name('hopadditions.store');