From b6f8a61e69f5499580df0660870f7d5a17a3b87e Mon Sep 17 00:00:00 2001 From: jk Date: Tue, 22 Jun 2021 09:51:22 +0100 Subject: [PATCH] beers refactor mkI --- app/Http/Controllers/SummarieController.php | 127 +++++++++++++++----- resources/views/beers.blade.php | 106 +--------------- resources/views/beers/create.blade.php | 68 +++++++++++ resources/views/beers/edit.blade.php | 67 +++++++++++ resources/views/beers/index.blade.php | 55 +++++++++ resources/views/summaries/create.blade.php | 0 resources/views/summaries/edit.blade.php | 0 resources/views/summaries/index.blade.php | 0 routes/web.php | 8 +- 9 files changed, 289 insertions(+), 142 deletions(-) create mode 100644 resources/views/beers/create.blade.php create mode 100644 resources/views/beers/edit.blade.php create mode 100644 resources/views/beers/index.blade.php delete mode 100644 resources/views/summaries/create.blade.php delete mode 100644 resources/views/summaries/edit.blade.php delete mode 100644 resources/views/summaries/index.blade.php diff --git a/app/Http/Controllers/SummarieController.php b/app/Http/Controllers/SummarieController.php index 4b7e2dc..4b4c54d 100644 --- a/app/Http/Controllers/SummarieController.php +++ b/app/Http/Controllers/SummarieController.php @@ -17,55 +17,116 @@ class SummarieController extends Controller public function index() { $beers = Summarie::orderBy('name')->get(); - foreach ($beers as $beer) - { - $brewery = DB::table('breweries')->where('id', $beer->brewery_id)->value('name'); - $beer['brewery'] = $brewery; - } - return view('beers')->with('summaries', $beers); + foreach ($beers as $beer) + { + $beer = DB::table('breweries')->where('id', $beer->beer_id)->value('name'); + $beer['beer'] = $beer; + } + return view('beers.index')->with('beers', $beers); } - public function store(Request $request){ + public function store(Request $request){ // validation $this->validate($request,[ 'name' => 'required', - 'type' => 'required', - 'abv' => 'required', - 'fg' => 'required', - 'keywords' => 'required', - 'og' => 'required', - 'source' => 'required', - 'batch' => 'required', - 'brewery_id' => 'required' + 'type' => 'required', + 'abv' => 'required', + 'fg' => 'required', + 'keywords' => 'required', + 'og' => 'required', + 'source' => 'required', + 'batch' => 'required', + 'beer_id' => 'required', + 'brewery_id' => 'required' ]); // create project - $beers = new Summarie; + $beer = new Summarie; $lastID = Summarie::orderBy('beer_id','desc')->value('beer_id'); - $beers->beer_id = number_format($lastID) + 1; - $beers->name = $request->input('name'); - $beers->type = $request->input('type'); - $beers->abv = $request->input('abv'); - $beers->fg = $request->input('fg'); - $beers->keywords = '{'.$request->input('keywords').'}'; + $beer->beer_id = number_format($lastID) + 1; + $beer->name = $request->input('name'); + $beer->type = $request->input('type'); + $beer->abv = $request->input('abv'); + $beer->fg = $request->input('fg'); + $beer->keywords = '{'.$request->input('keywords').'}'; if ($request->mine) - { - $beers->mine = true; - } else { - $beers->mine = false; - } - $beers->og = $request->input('og'); - $beers->source = $request->input('source'); - $beers->batch = $request->input('batch'); - $beers->brewery_id = $request->input('brewery_id'); + { + $beer->mine = true; + } else { + $beer->mine = false; + } + $beer->og = $request->input('og'); + $beer->source = $request->input('source'); + $beer->batch = $request->input('batch'); + $beer->beer_id = $request->input('beer_id'); + $beer->brewery_id = $request->input('brewery_id'); if ($request->input('notes')) { - $beers->notes = $request->input('notes'); + $beer->notes = $request->input('notes'); } - $beers->save(); + $beer->save(); return redirect('/beers')->with('success', 'Beer Added'); } + public function edit($id){ + $beer = Summarie::where('id', (int)$id)->first(); + return view('beers.edit')->with('beer', $beer); + } + + public function update(Request $request, $id) + { + $request->validate([ + 'name' => 'required', + 'type' => 'required', + 'abv' => 'required', + 'fg' => 'required', + 'keywords' => 'required', + 'og' => 'required', + 'source' => 'required', + 'batch' => 'required', + 'beer_id' => 'required', + 'brewery_id' => 'required' + ]); + + $beer = Summarie::where('id', $id)->first(); + $beer->name = $request->input('name'); + $beer->type = $request->input('type'); + $beer->abv = $request->input('abv'); + $beer->fg = $request->input('fg'); + $beer->keywords = '{'.$request->input('keywords').'}'; + if ($request->mine) + { + $beer->mine = true; + } else { + $beer->mine = false; + } + $beer->og = $request->input('og'); + $beer->source = $request->input('source'); + $beer->batch = $request->input('batch'); + $beer->beer_id = $request->input('beer_id'); + $beer->brewery_id = $request->input('beer_id'); + if ($request->input('notes')) + { + $beer->notes = $request->input('notes'); + } + $beer->save(); + + return redirect('/beers')->with('success', 'Beer updated!'); + } + public function create() + { + return view('beers.create'); + } + public function destroy($id) + { + $beer = Summarie::find($id); + $beer->delete(); + + return redirect('/beers')->with('success', 'Beer deleted!'); + } + + + } diff --git a/resources/views/beers.blade.php b/resources/views/beers.blade.php index 82b2baa..9ede88a 100644 --- a/resources/views/beers.blade.php +++ b/resources/views/beers.blade.php @@ -1,110 +1,8 @@ @extends('layouts.app') @section('content') -
-
-
-
-@include('inc.navbar') -
Home -> {{ __('Beer List') }}Go Back
- -
-@if (Auth::user()->isAdmin()) - -
-@endif - - - @include('inc.messages') - - - - - - - - - - @foreach ($summaries as $summary) - - - - - - @endforeach - -
NameBreweryStyle
{{$summary->name}} {{$summary->brewery}} {{$summary->type}}
-
-
-
-
-
- -