Browse Source

mashes refactor mkI

master
jk 3 years ago
parent
commit
69cad77992
  1. 72
      app/Http/Controllers/MasheController.php
  2. 63
      resources/views/mashes.blade.php
  3. 44
      resources/views/mashes/create.blade.php
  4. 43
      resources/views/mashes/edit.blade.php
  5. 53
      resources/views/mashes/index.blade.php
  6. 3
      routes/web.php

72
app/Http/Controllers/MasheController.php

@ -4,6 +4,7 @@ namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Mashe;
use App\Models\Summarie;
class MasheController extends Controller
{
@ -14,8 +15,13 @@ class MasheController extends Controller
public function index()
{
$project = Mashe::get();
return view('mashes')->with('mashes', $project);
$mashes = Mashe::get();
foreach ($mashes as $mash)
{
$beername = Summarie::where('beer_id', $mash->beer_id)->value('name');
$mash['beer'] = $beername;
}
return view('mashes.index')->with('mashes', $mashes);
}
@ -29,19 +35,53 @@ class MasheController extends Controller
'boil' => 'required',
]);
// create project
$mashes = new Mashe;
$lastID = Mashe::orderBy('id','desc')->value('id');
$mashes->id = number_format($lastID) + 1;
$mashes->beer_id = $request->input('beer_id');
$mashes->temperature = $request->input('temperature');
$mashes->duration = $request->input('duration');
$mashes->stage = $request->input('stage');
$mashes->boil = $request->input('boil');
$mashes->save();
return redirect('/mashes')->with('success', 'Mash Step Added');
}
//
$mash = new Mashe;
$lastID = Mashe::orderBy('id','desc')->take(1)->value('id');
$mash->id = number_format($lastID) + 1;
$mash->beer_id = $request->input('beer_id');
$mash->temp = $request->input('temperature');
$mash->duration = $request->input('duration');
$mash->stage = $request->input('stage');
$mash->boil = $request->input('boil');
$mash->save();
return redirect('/mashes')->with('success', 'Mash Step Added!');
}
public function edit($id){
$mash = Mashe::where('id', (int)$id)->first();
return view('mashes.edit')->with('mash', $mash);
}
public function update(Request $request, $id){
// validation
$this->validate($request,[
'beer_id' => 'required',
'temperature' => 'required',
'duration' => 'required',
'stage' => 'required',
'boil' => 'required',
]);
$mash = Mashe::where('id', (int)$id)->first();
$mash->beer_id = $request->input('beer_id');
$mash->temp = $request->input('temperature');
$mash->duration = $request->input('duration');
$mash->stage = $request->input('stage');
$mash->boil = $request->input('boil');
$mash->save();
return redirect('/mashs')->with('success', 'Mash Step Updated!');
}
public function create()
{
return view('mashes.create');
}
public function destroy($id)
{
$mash = Mashe::find($id);
$mash->delete();
return redirect('/mashes')->with('success', 'Mash Step Deleted!');
}
}

63
resources/views/mashes.blade.php

@ -1,67 +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> -> {{ __('Mash Steps') }}<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 Mash 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 Grain</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('mash.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="">Temperature</label>
<input type="text" class="form-control" name="temp" >
</div>
<div class="form-group">
<label for="">Duration</label>
<input type="text" class="form-control" name="duration">
</div>
<div class="form-group">
<label for="">Stage</label>
<input type="text" class="form-control" name="stage">
</div>
<div class="form-group">
<label for="">Length of Boil</label>
<input type="text" class="form-control" name="boil">
</div>
<input type="submit" name="submit" value="Submit" class="btn btn-success">
</form>
</div>
</div>
</div>
<div class="container">
@yield('main')
</div>
@endsection

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

@ -0,0 +1,44 @@
@extends('mashes')
@section('main')
<div class="row">
<div class="col-sm-8 offset-sm-2">
<h1 class="display-3">Add a Mash Step</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('mashes.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="temperature">Temperature</label>
<input type="text" class="form-control" name="temperature" >
</div>
<div class="form-group">
<label for="duration">Duration</label>
<input type="text" class="form-control" name="duration">
</div>
<div class="form-group">
<label for="stage">Stage</label>
<input type="text" class="form-control" name="stage">
</div>
<div class="form-group">
<label for="boil">Length of Boil</label>
<input type="text" class="form-control" name="boil">
</div>
<button type="submit" class="btn btn-primary">Add Mash Step</button>
</form>
</div>
</div>
</div>
@endsection

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

@ -0,0 +1,43 @@
@extends('mashes')
@section('main') <div class="row">
<div class="col-sm-12 offset-sm-2">
<h1 class="display-3">Update Grain Bill</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('mashes.update', $mash->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="{{$mash->beer_id}}" />
</div>
<div class="form-group">
<label for="temp">Temperature</label>
<input type="text" class="form-control" name="temp" value="{{$mash->temp}}" />
</div>
<div class="form-group">
<label for="duration">Duration</label>
<input type="text" class="form-control" name="duration" value="{{$mash->duration}}" />
</div>
<div class="form-group">
<label for="stage">Stage</label>
<input type="text" class="form-control" name="stage" value="{{$mash->stage}}" />
</div>
<div class="form-group">
<label for="boil">Length of Boil</label>
<input type="text" class="form-control" name="boil" value="{{$mash->boil}}" />
</div>
<button type="submit" class="btn btn-primary">Update</button>
</form>
</div>
</div>
@endsection

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

@ -0,0 +1,53 @@
@extends('mashes')
@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> -> {{ __('Mash Steps') }}<span class="backlink"><a href="{{url()->previous()}}">Go Back</a></span></div>
<div class="card-body">
@if (Auth::user()->isAdmin())
<a href="{{ route('mashes.create') }}" class="btn btn-primary">Add Mash 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">Beer</th>
<th scope="col">Temperature</th>
<th scope="col">Duration</th>
<th scope="col">Stage</th>
<th scope="col">Length of Boil</th>
@if (Auth::user()->isAdmin())<th colspan="2" scope="col">Admin</th>@endif
<tbody>
@foreach ($mashes as $mash)
<tr>
<td><a href="/beer/{{$mash->beer_id}}">{{$mash->beer}}</a> </td>
<td>{{$mash->temperature}} </td>
<td>{{$mash->duration}} </td>
<td>{{$mash->stage}} </td>
<td>{{$mash->boil}} </td>
@if (Auth::user()->isAdmin())
<td><a href="{{ route('mashes.edit',$mash->id)}}" class="btn btn-primary">Edit</a></td>
<td><form action="{{ route('mashes.destroy', $mash->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

3
routes/web.php

@ -29,9 +29,9 @@ Route::resource('hops', 'App\Http\Controllers\HopController');
Route::resource('yeasts', 'App\Http\Controllers\YeastController');
Route::resource('adjuncts', 'App\Http\Controllers\AdjunctController');
Route::resource('grainbills', 'App\Http\Controllers\GrainbillController');
Route::resource('mashes', 'App\Http\Controllers\MasheController');
Route::get('/home', [App\Http\Controllers\SummarieController::class, 'index'])->name('home');
Route::get('/fermentations', [App\Http\Controllers\FermentationController::class, 'index'])->name('fermentations');
Route::get('/mashes', [App\Http\Controllers\MasheController::class, 'index'])->name('mashes');
Route::get('/hopadditions', [App\Http\Controllers\HopAdditionController::class, 'index'])->name('hopadditions');
Route::get('/adjunctadditions', [App\Http\Controllers\AdjunctAdditionController::class, 'index'])->name('adjunctadditions');
Route::get('/brewery/{breweryID}', [App\Http\Controllers\BreweryController::class, 'index'])->name('brewery');
@ -40,7 +40,6 @@ 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('/mashes', [App\Http\Controllers\MasheController::class, 'store'])->name('mash.store');
Route::post('/hopadditions', [App\Http\Controllers\HopAdditionController::class, 'store'])->name('hopadditions.store');
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