Browse Source

fermentations refactor mkI

master
jk 3 years ago
parent
commit
8be7d3b11c
  1. 52
      app/Http/Controllers/FermentationController.php
  2. 44
      resources/views/fermentation/create.blade.php
  3. 43
      resources/views/fermentation/edit.blade.php
  4. 53
      resources/views/fermentation/index.blade.php
  5. 62
      resources/views/fermentations.blade.php
  6. 4
      resources/views/hopadditions/create.blade.php
  7. 3
      routes/web.php

52
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,7 +39,7 @@ 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');
@ -44,5 +53,42 @@ class FermentationController extends Controller
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!');
}
}

44
resources/views/fermentation/create.blade.php

@ -0,0 +1,44 @@
@extends('fermentations')
@section('main')
<div class="row">
<div class="col-sm-12 offset-sm-2">
<h1 class="display-3">Add a Grain</h1>
<div>
@if ($errors->any())
<div class="alert alert-danger">
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div><br />
@endif
<form method="post" action="{{ route('fermentations.store') }}">
@csrf
<div class="form-group">
<label for="beer_id">Beer ID</label>
<input type="text" class="form-control" name="beer_id">
</div>
<div class="form-group">
<label for="yeast_id">Yeast ID</label>
<input type="text" class="form-control" name="yeast_id" >
</div>
<div class="form-group">
<label for="temperature">Temperature</label>
<input type="text" class="form-control" name="temperature">
</div>
<div class="form-group">
<label for="duration">Duration</label>
<textarea type="text" class="form-control" name="duration"></textarea>
</div>
<div class="form-group">
<label for="alternative">Alternative (ID)</label>
<input type="text" class="form-control" name="alternative">
</div>
<button type="submit" class="btn btn-primary">Add Grain</button>
</form>
</div>
</div>
</div>
@endsection

43
resources/views/fermentation/edit.blade.php

@ -0,0 +1,43 @@
@extends('fermentations')
@section('main') <div class="row">
<div class="col-sm-12 offset-sm-2">
<h1 class="display-3">Update Fermentation Step</h1>
@if ($errors->any())
<div class="alert alert-danger">
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
<br />
@endif
<form method="post" action="{{ route('fermentations.update', $fermentation->id) }}">
@method('PATCH')
@csrf
<div class="form-group">
<label for="beer_id">Beer ID</label>
<input type="text" class="form-control" name="beer_id" value="{{@fermentation->beer_id}}" />
</div>
<div class="form-group">
<label for="yeast_id">Yeast ID</label>
<input type="text" class="form-control" name="yeast_id" value="{{@fermentation->yeast_id}}" />
</div>
<div class="form-group">
<label for="temperature">Temperature</label>
<input type="text" class="form-control" name="temperature" value="{{@fermentation->temperature}}" />
</div>
<div class="form-group">
<label for="duration">Duration</label>
<textarea type="text" class="form-control" name="duration">{{@fermentation->duration}}</textarea>
</div>
<div class="form-group">
<label for="alternative">Alternative (ID)</label>
<input type="text" class="form-control" name="alternative" value="{{@fermentation->alternative}}" />
</div>
<button type="submit" class="btn btn-primary">Update</button>
</form>
</div>
</div>
@endsection

53
resources/views/fermentation/index.blade.php

@ -0,0 +1,53 @@
@extends('fermentations')
@section('main')
<div class="container">
<div class="row justify-content-center">
<div class="col-md-12">
<div class="card">
@include('inc.navbar')
<div class="card-header"><a href="/home">Home</a> -> {{ __('Fermentation Instructions') }}<span class="backlink"><a href="{{url()->previous()}}">Go Back</a></span></div>
<div class="card-body">
@if (Auth::user()->isAdmin())
<a href="{{ route('fermentations.create') }}" class="btn btn-primary">Add Fermentation Step</a>
<hr/>
@endif
<table class="table table-striped table-dark" id="table-programs">
<!-- This piece of code is for error messages display purposes -->
@include('inc.messages')
<thead>
<tr>
<th scope="col">Yeast</th>
<th scope="col">Beer</th>
<th scope="col">Temperature</th>
<th scope="col">Duration</th>
<th scope="col">Alternative</th>
@if (Auth::user()->isAdmin())<th colspan="2" scope="col">Admin</th>@endif
<tbody>
@foreach ($fermentations as $fermentation)
<tr>
<td><a href="/yeast/{{$fermentation->yeast_id}}">{{$fermentation->name}}</a> </td>
<td><a href="/beer/{{$fermentation->beer_id}}">{{$fermentation->beer}}</a> </td>
<td>{{$fermentation->temperature}} </td>
<td>{{$fermentation->duration}} </td>
<td>{{$fermentation->alternative}} </td>
@if (Auth::user()->isAdmin())
<td><a href="{{ route('fermentations.edit',$fermentation->id)}}" class="btn btn-primary">Edit</a></td>
<td><form action="{{ route('fermentations.destroy', $fermentation->id)}}" method="post">
@csrf
@method('DELETE')
<button class="btn btn-danger" type="submit">Delete</button>
</form></td>
@endif
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
@endsection

62
resources/views/fermentations.blade.php

@ -1,66 +1,8 @@
@extends('layouts.app')
@section('content')
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
@include('inc.navbar')
<div class="card-header"><a href="/home">Home</a> -> {{ __('Fermentation Instructions') }}<span class="backlink"><a href="{{url()->previous()}}">Go Back</a></span></div>
<div class="card-body">
@if (Auth::user()->isAdmin())
<button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#addModal" type="button" name="button" >
Add Fermentation Step
</button>
<hr/>
@endif
<!-- This piece of code is for error messages display purposes -->
@include('inc.messages')
</div>
</div>
</div>
</div>
</div>
<!-- this code if for the modal -->
<div class="modal fade bg-primary text-dark" tabindex="-1" role="dialog" id="addModal">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Add Fermentation</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close" >
<span aria-hidden="true">x</span>
</button>
</div>
<div class="modal-body">
<form class="" action="{{route('fermentations.store')}}" method="post">
{{csrf_field()}}
<div class="form-group">
<label for="">Beer ID</label>
<input type="text" class="form-control" name="beer_id">
</div>
<div class="form-group">
<label for="">Yeast ID</label>
<input type="text" class="form-control" name="yeast_id" >
</div>
<div class="form-group">
<label for="">Temperature</label>
<input type="text" class="form-control" name="temperature">
</div>
<div class="form-group">
<label for="">Duration</label>
<textarea type="text" class="form-control" name="duration"></textarea>
</div>
<div class="form-group">
<label for="">Alternative (ID)</label>
<input type="text" class="form-control" name="alternative">
</div>
<input type="submit" name="submit" value="Submit" class="btn btn-success">
</form>
</div>
</div>
</div>
<div class="container">
@yield('main')
</div>
@endsection

4
resources/views/hopadditions/create.blade.php

@ -3,7 +3,7 @@
@section('main')
<div class="row">
<div class="col-sm-12 offset-sm-2">
<h1 class="display-3">Add a Grain</h1>
<h1 class="display-3">Add a Hop Addition</h1>
<div>
@if ($errors->any())
<div class="alert alert-danger">
@ -32,7 +32,7 @@
<label for="timing">Timing</label>
<input type="text" class="form-control" name="timing">
</div>
<button type="submit" class="btn btn-primary">Add Grain</button>
<button type="submit" class="btn btn-primary">Add Hop Addition</button>
</form>
</div>
</div>

3
routes/web.php

@ -31,8 +31,8 @@ Route::resource('adjuncts', 'App\Http\Controllers\AdjunctController');
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::get('/home', [App\Http\Controllers\SummarieController::class, 'index'])->name('home');
Route::get('/fermentations', [App\Http\Controllers\FermentationController::class, 'index'])->name('fermentations');
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');
@ -41,4 +41,3 @@ Route::get('/yeast/{yeastID}', [App\Http\Controllers\YeastcardController::class,
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');
Route::post('/fermentations', [App\Http\Controllers\FermentationController::class, 'store'])->name('fermentations.store');
Loading…
Cancel
Save