Browse Source

adjunctadditions refactor mkI

master
jk 3 years ago
parent
commit
fedaff7abf
  1. 56
      app/Http/Controllers/AdjunctAdditionController.php
  2. 65
      resources/views/adjunctadditions.blade.php
  3. 48
      resources/views/adjunctadditions/create.blade.php
  4. 47
      resources/views/adjunctadditions/edit.blade.php
  5. 54
      resources/views/adjunctadditions/index.blade.php
  6. 3
      routes/web.php

56
app/Http/Controllers/AdjunctAdditionController.php

@ -4,6 +4,8 @@ namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Adjunctaddition;
use App\Models\Adjunct;
use App\Models\Summarie;
class AdjunctAdditionController extends Controller
{
@ -14,8 +16,17 @@ class AdjunctAdditionController extends Controller
public function index()
{
$project = Adjunctaddition::get();
return view('adjunctadditions')->with('adjunctadditions', $project);
$adjunctadditions = Adjunctaddition::get();
foreach ($adjunctadditions as $adjunctaddition)
{
$beername = Summarie::where('beer_id', $adjunctaddition->beer_id)->value('name');
$adjunctname = Adjunct::where('id', $adjunctaddition->adjunct_id)->value('name');
$altname = = Adjunct::where('id', $adjunctaddition->alternative)->value('name');
$adjunctaddition['beer'] = $beername;
$adjunctaddition['name'] = $adjunctname;
$adjunctaddition['alternativename'] = $altname;
}
return view('adjunctadditions.index')->with('adjunctadditions', $project);
}
@ -27,11 +38,9 @@ class AdjunctAdditionController extends Controller
'amount' => 'required',
'timing' => 'required',
]);
// create project
$adjunct = new Adjunctaddition;
$lastID = Adjunctaddition::orderBy('id','desc')->value('id');
$lastID = Adjunctaddition::orderBy('id','desc')->take(1)->value('id');
$adjunct->id = number_format($lastID) + 1;
$adjunct->beer_id = $request->input('beer_id');
$adjunct->adjunct_id = $request->input('adjunct_id');
@ -44,4 +53,41 @@ class AdjunctAdditionController extends Controller
return redirect('/adjunctadditions')->with('success', 'Adjunct Addition Added');
}
public function edit($id){
$adjunctaddition = Adjunctaddition::where('id', (int)$id)->first();
return view('adjunctadditions.edit')->with('adjunctaddition', $adjunctaddition);
}
public function update(Request $request, $id){
// validation
$this->validate($request,[
'beer_id' => 'required',
'adjunct_id' => 'required',
'amount' => 'required',
'timing' => 'required',
]);
$adjunct = Adjunctaddition::where('id', (int)$id)->first();
$adjunct->beer_id = $request->input('beer_id');
$adjunct->adjunct_id = $request->input('adjunct_id');
$adjunct->amount = $request->input('amount');
$adjunct->timing = $request->input('timing');
$adjunct->alternative = $request->input('alternative');
$adjunct->notes = $request->input('notes');
$adjunct->save();
return redirect('/adjunctadditions')->with('success', 'Adjunct Addition Updated!');
}
public function create()
{
return view('adjunctadditions.create');
}
public function destroy($id)
{
$adjunctaddition = Adjunctaddition::find($id);
$adjunctaddition->delete();
return redirect('/adjunctadditions')->with('success', 'Adjunct Addition deleted!');
}
}

65
resources/views/adjunctadditions.blade.php

@ -1,69 +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> -> {{ __('Adjunct Additions') }}<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 Adjunct Addition
</button>
@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('adjunctadditions.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="">Adjunct ID</label>
<input type="text" class="form-control" name="adjunct_id" >
</div>
<div class="form-group">
<label for="">Amount</label>
<input type="text" class="form-control" name="amount">
</div>
<div class="form-group">
<label for="">Timing</label>
<input type="text" class="form-control" name="timing">
</div>
<div class="form-group">
<label for="">Alternative (ID)</label>
<input type="text" class="form-control" name="alternative">
</div>
<div class="form-group">
<label for="">Notes</label>
<textarea type="text" class="form-control" name="notes"></textarea>
</div>
<input type="submit" name="submit" value="Submit" class="btn btn-success">
</form>
</div>
</div>
</div>
<div class="container">
@yield('main')
</div>
@endsection

48
resources/views/adjunctadditions/create.blade.php

@ -0,0 +1,48 @@
@extends('adjunctadditions')
@section('main')
<div class="row">
<div class="col-sm-12 offset-sm-2">
<h1 class="display-3">Add an Adjunct Addition</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('adjunctadditions.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="adjunct_id">Adjunct ID</label>
<input type="text" class="form-control" name="adjunct_id" >
</div>
<div class="form-group">
<label for="amount">Amount</label>
<input type="text" class="form-control" name="amount">
</div>
<div class="form-group">
<label for="timing">Timing</label>
<input type="text" class="form-control" name="timing">
</div>
<div class="form-group">
<label for="alternative">Alternative (ID)</label>
<input type="text" class="form-control" name="alternative">
</div>
<div class="form-group">
<label for="notes">Notes</label>
<textarea type="text" class="form-control" name="notes"></textarea>
</div>
<button type="submit" class="btn btn-primary">Add Adjunct Addition</button>
</form>
</div>
</div>
</div>
@endsection

47
resources/views/adjunctadditions/edit.blade.php

@ -0,0 +1,47 @@
@extends('adjunctadditions')
@section('main') <div class="row">
<div class="col-sm-12 offset-sm-2">
<h1 class="display-3">Update Adjunct Addition</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('adjunctadditions.update', $adjunctaddition->id) }}">
@method('PATCH')
@csrf
up">
<label for="beer_id">Beer ID</label>
<input type="text" class="form-control" name="beer_id" value="{{$adjunctaddition->beer_id}}" />
</div>
<div class="form-group">
<label for="adjunct_id">Adjunct ID</label>
<input type="text" class="form-control" name="adjunct_id" value="{{$adjunctaddition->adjunct_id}}" />
</div>
<div class="form-group">
<label for="amount">Amount</label>
<input type="text" class="form-control" name="amount" value="{{$adjunctaddition->amount}}" />
</div>
<div class="form-group">
<label for="timing">Timing</label>
<input type="text" class="form-control" name="timing" value="{{$adjunctaddition->timing}}" />
</div>
<div class="form-group">
<label for="alternative">Alternative (ID)</label>
<input type="text" class="form-control" name="alternative" value="{{$adjunctaddition->alternative}}" />
</div>
<div class="form-group">
<label for="notes">Notes</label>
<textarea type="text" class="form-control" name="notes">{{$adjunctaddition->notes}}</textarea>
</div>
<button type="submit" class="btn btn-primary">Update</button>
</form>
</div>
</div>
@endsection

54
resources/views/adjunctadditions/index.blade.php

@ -0,0 +1,54 @@
@extends('adjunctadditions')
@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> -> {{ __('Adjunct Additions') }}<span class="backlink"><a href="{{url()->previous()}}">Go Back</a></span></div>
<div class="card-body">
@if (Auth::user()->isAdmin())
<a href="{{ route('adjunctadditions.create') }}" class="btn btn-primary">Add Adjunct Addition</a>
@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">Adjunct</th>
<th scope="col">Beer</th>
<th scope="col">Amount</th>
<th scope="col">Timing</th>
<th scope="col">Alternative</th>
<th scope="col">Notes</th>
@if (Auth::user()->isAdmin())<th colspan="2" scope="col">Admin</th>@endif
<tbody>
@foreach ($adjunctadditions as $adjunctaddition)
<tr>
<td><a href="/adjunct/{{$adjunctaddition->adjunct_id}}">{{$adjunctaddition->name}}</a> </td>
<td><a href="/beer/{{$adjunctaddition->beer_id}}">{{$adjunctaddition->beer}}</a> </td>
<td>{{$adjunctaddition->amount}} </td>
<td>{{$adjunctaddition->timing}} </td>
<td><a href="/adjunct/{{$adjunctaddition->alternative}}">{{$adjunctaddition->alternativename}}</a> </td>
<td>{{$adjunctaddition->notes}} </td>
@if (Auth::user()->isAdmin())
<td><a href="{{ route('adjunctadditions.edit',$adjunctaddition->id)}}" class="btn btn-primary">Edit</a></td>
<td><form action="{{ route('adjunctadditions.destroy', $adjunctaddition->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

@ -32,12 +32,11 @@ 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::resource('adjunctadditions', 'App\Http\Controllers\AdjunctAdditionController');
Route::get('/home', [App\Http\Controllers\SummarieController::class, 'index'])->name('home');
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');
Route::get('/grain/{grainID}', [App\Http\Controllers\GraincardController::class, 'index'])->name('grain');
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('/adjunctadditions', [App\Http\Controllers\AdjunctAdditionController::class, 'store'])->name('adjunctadditions.store');
Loading…
Cancel
Save