diff --git a/app/Http/Controllers/FermentationController.php b/app/Http/Controllers/FermentationController.php index b3ad804..605a499 100644 --- a/app/Http/Controllers/FermentationController.php +++ b/app/Http/Controllers/FermentationController.php @@ -4,6 +4,8 @@ namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Models\Fermentation; +use App\Models\Yeast; +use App\Models\Summarie; class FermentationController extends Controller { public function __construct() @@ -13,8 +15,15 @@ class FermentationController extends Controller public function index() { - $project = Fermentation::get(); - return view('fermentations')->with('fermentations', $project); + $fermentations = Fermentation::get(); + foreach ($fermentations as $fermentation) + { + $beername = Summarie::where('beer_id', $fermentation->beer_id)->value('name'); + $yeastname = Yeast::where('id', $fermentation->yeast_id)->value('name'); + $fermentation['beer'] = $beername; + $fermentation['name'] = $yeastname; + } + return view('fermentations.index')->with('fermentations', $fermentations); } @@ -30,19 +39,56 @@ class FermentationController extends Controller // create project $yeast = new Fermentations; - $lastID = Fermentations::orderBy('id','desc')->value('id'); + $lastID = Fermentations::orderBy('id','desc')->take(1)->value('id'); $yeast->id = number_format($lastID) + 1; $yeast->beer_id = $request->input('beer_id'); $yeast->yeast_id = $request->input('yeast_id'); $yeast->temperature = $request->input('temperature'); $yeast->duration = $request->input('duration'); - if ($request->input('alternative')) - { - $yeast->alternative = $request->input('alternative'); - } + if ($request->input('alternative')) + { + $yeast->alternative = $request->input('alternative'); + } $yeast->save(); return redirect('/fermnentations')->with('success', 'Fermentation Step Added'); } + public function edit($id){ + $fermentation = Fermentation::where('id', (int)$id)->first(); + return view('fermentations.edit')->with('fermentation', $fermentation); + } + + public function update(Request $request, $id){ + // validation + $this->validate($request,[ + 'beer_id' => 'required', + 'yeast_id' => 'required', + 'temperature' => 'required', + 'duration' => 'required', + ]); + $yeast = Fermentation::where('id', (int)$id)->first(); + $yeast->beer_id = $request->input('beer_id'); + $yeast->yeast_id = $request->input('yeast_id'); + $yeast->temperature = $request->input('temperature'); + $yeast->duration = $request->input('duration'); + if ($request->input('alternative')) + { + $yeast->alternative = $request->input('alternative'); + } + $yeast->save(); + + return redirect('/fermentations')->with('success', 'Fermentation Step Updated!'); + } + public function create() + { + return view('fermentations.create'); + } + public function destroy($id) + { + $fermentation = Fermentation::find($id); + $fermentation->delete(); + + return redirect('/fermentations')->with('success', 'Fermentation Step deleted!'); + } } diff --git a/resources/views/fermentation/create.blade.php b/resources/views/fermentation/create.blade.php index e69de29..9b5ebc3 100644 --- a/resources/views/fermentation/create.blade.php +++ b/resources/views/fermentation/create.blade.php @@ -0,0 +1,44 @@ +@extends('fermentations') + +@section('main') +
+
+

Add a Grain

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

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

Update Fermentation Step

+ + @if ($errors->any()) +
+
    + @foreach ($errors->all() as $error) +
  • {{ $error }}
  • + @endforeach +
+
+
+ @endif +
+ @method('PATCH') + @csrf +
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+ +
+
+
+@endsection diff --git a/resources/views/fermentation/index.blade.php b/resources/views/fermentation/index.blade.php index e69de29..668d325 100644 --- a/resources/views/fermentation/index.blade.php +++ b/resources/views/fermentation/index.blade.php @@ -0,0 +1,53 @@ +@extends('fermentations') + +@section('main') +
+
+
+
+@include('inc.navbar') +
Home -> {{ __('Fermentation Instructions') }}Go Back
+ +
+@if (Auth::user()->isAdmin()) + Add Fermentation Step +
+@endif + + + @include('inc.messages') + + + + + + + + @if (Auth::user()->isAdmin())@endif + + @foreach ($fermentations as $fermentation) + + + + + + + @if (Auth::user()->isAdmin()) + + + @endif + + @endforeach + +
YeastBeerTemperatureDurationAlternativeAdmin
{{$fermentation->name}} {{$fermentation->beer}} {{$fermentation->temperature}} {{$fermentation->duration}} {{$fermentation->alternative}} Edit
+ @csrf + @method('DELETE') + +
+
+
+
+
+
+ +@endsection diff --git a/resources/views/fermentations.blade.php b/resources/views/fermentations.blade.php index b5d058f..9ede88a 100644 --- a/resources/views/fermentations.blade.php +++ b/resources/views/fermentations.blade.php @@ -1,66 +1,8 @@ @extends('layouts.app') @section('content') -
-
-
-
-@include('inc.navbar') -
Home -> {{ __('Fermentation Instructions') }}Go Back
- -
-@if (Auth::user()->isAdmin()) - -
-@endif - - @include('inc.messages') -
-
-
-
-
- -