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 @@ -
{{$grain->name}} | + @if (Auth::user()->isAdmin()) +Edit | ++ @endif + |