Browse Source

beers refactor mkI

master
jk 3 years ago
parent
commit
b6f8a61e69
  1. 97
      app/Http/Controllers/SummarieController.php
  2. 106
      resources/views/beers.blade.php
  3. 68
      resources/views/beers/create.blade.php
  4. 67
      resources/views/beers/edit.blade.php
  5. 55
      resources/views/beers/index.blade.php
  6. 0
      resources/views/summaries/create.blade.php
  7. 0
      resources/views/summaries/edit.blade.php
  8. 0
      resources/views/summaries/index.blade.php
  9. 8
      routes/web.php

97
app/Http/Controllers/SummarieController.php

@ -19,10 +19,10 @@ class SummarieController extends Controller
$beers = Summarie::orderBy('name')->get(); $beers = Summarie::orderBy('name')->get();
foreach ($beers as $beer) foreach ($beers as $beer)
{ {
$brewery = DB::table('breweries')->where('id', $beer->brewery_id)->value('name');
$beer['brewery'] = $brewery;
$beer = DB::table('breweries')->where('id', $beer->beer_id)->value('name');
$beer['beer'] = $beer;
} }
return view('beers')->with('summaries', $beers);
return view('beers.index')->with('beers', $beers);
} }
public function store(Request $request){ public function store(Request $request){
@ -36,36 +36,97 @@ class SummarieController extends Controller
'og' => 'required', 'og' => 'required',
'source' => 'required', 'source' => 'required',
'batch' => 'required', 'batch' => 'required',
'beer_id' => 'required',
'brewery_id' => 'required' 'brewery_id' => 'required'
]); ]);
// create project // create project
$beers = new Summarie;
$beer = new Summarie;
$lastID = Summarie::orderBy('beer_id','desc')->value('beer_id'); $lastID = Summarie::orderBy('beer_id','desc')->value('beer_id');
$beers->beer_id = number_format($lastID) + 1;
$beers->name = $request->input('name');
$beers->type = $request->input('type');
$beers->abv = $request->input('abv');
$beers->fg = $request->input('fg');
$beers->keywords = '{'.$request->input('keywords').'}';
$beer->beer_id = number_format($lastID) + 1;
$beer->name = $request->input('name');
$beer->type = $request->input('type');
$beer->abv = $request->input('abv');
$beer->fg = $request->input('fg');
$beer->keywords = '{'.$request->input('keywords').'}';
if ($request->mine) if ($request->mine)
{ {
$beers->mine = true;
$beer->mine = true;
} else { } else {
$beers->mine = false;
$beer->mine = false;
} }
$beers->og = $request->input('og');
$beers->source = $request->input('source');
$beers->batch = $request->input('batch');
$beers->brewery_id = $request->input('brewery_id');
$beer->og = $request->input('og');
$beer->source = $request->input('source');
$beer->batch = $request->input('batch');
$beer->beer_id = $request->input('beer_id');
$beer->brewery_id = $request->input('brewery_id');
if ($request->input('notes')) if ($request->input('notes'))
{ {
$beers->notes = $request->input('notes');
$beer->notes = $request->input('notes');
} }
$beers->save();
$beer->save();
return redirect('/beers')->with('success', 'Beer Added'); return redirect('/beers')->with('success', 'Beer Added');
} }
public function edit($id){
$beer = Summarie::where('id', (int)$id)->first();
return view('beers.edit')->with('beer', $beer);
}
public function update(Request $request, $id)
{
$request->validate([
'name' => 'required',
'type' => 'required',
'abv' => 'required',
'fg' => 'required',
'keywords' => 'required',
'og' => 'required',
'source' => 'required',
'batch' => 'required',
'beer_id' => 'required',
'brewery_id' => 'required'
]);
$beer = Summarie::where('id', $id)->first();
$beer->name = $request->input('name');
$beer->type = $request->input('type');
$beer->abv = $request->input('abv');
$beer->fg = $request->input('fg');
$beer->keywords = '{'.$request->input('keywords').'}';
if ($request->mine)
{
$beer->mine = true;
} else {
$beer->mine = false;
}
$beer->og = $request->input('og');
$beer->source = $request->input('source');
$beer->batch = $request->input('batch');
$beer->beer_id = $request->input('beer_id');
$beer->brewery_id = $request->input('beer_id');
if ($request->input('notes'))
{
$beer->notes = $request->input('notes');
}
$beer->save();
return redirect('/beers')->with('success', 'Beer updated!');
}
public function create()
{
return view('beers.create');
}
public function destroy($id)
{
$beer = Summarie::find($id);
$beer->delete();
return redirect('/beers')->with('success', 'Beer deleted!');
}
} }

106
resources/views/beers.blade.php

@ -1,110 +1,8 @@
@extends('layouts.app') @extends('layouts.app')
@section('content') @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> -> {{ __('Beer List') }}<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 Beer
</button>
<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">Name</th>
<th scope="col">Brewery</th>
<th scope="col">Style</th>
</tr>
</thead>
<tbody>
@foreach ($summaries as $summary)
<tr>
<td><a href="/beer/{{$summary->beer_id}}">{{$summary->name}}</a> </td>
<td><a href="/brewery/{{$summary->brewery_id}}">{{$summary->brewery}}</a> </td>
<td>{{$summary->type}} </td>
</tr>
@endforeach
</tbody>
</table>
</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 Beer</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('beers.store')}}" method="post">
{{csrf_field()}}
<div class="form-group">
<label for="">Name</label>
<input type="text" class="form-control" name="name">
</div>
<div class="form-group">
<label for="">Keywords</label>
<textarea type="text" class="form-control" name="keywords" ></textarea>
</div>
<div class="Type">
<label for="">Colour</label>
<input type="text" class="form-control" name="type">
</div>
<div class="form-group">
<label for="">ABV %</label>
<input type="text" class="form-control" name="abv">
</div>
<div class="form-group">
<label for="">Original Gravity (OG)</label>
<input type="text" class="form-control" name="og">
</div>
<div class="form-group">
<label for="">Final Gravity (FG)</label>
<input type="text" class="form-control" name="fg">
</div>
<div class="form-group">
<label for="">Source</label>
<input type="text" class="form-control" name="source">
</div>
<div class="form-group">
<label for="">Notes</label>
<textarea type="text" class="form-control" name="notes"></textarea>
</div>
<div class="form-group">
<label for="">Brewery ID</label>
<input type="text" class="form-control" name="brewery_id">
</div>
<div class="form-group">
<label for="">Batch Size (L)</label>
<input type="text" class="form-control" name="batch">
</div>
<div class="form-group">
<label for="">Mine?</label>
<input type="checkbox" class="form-control" name="mine" checked>
</div>
<input type="submit" name="submit" value="Submit" class="btn btn-success">
</form>
</div>
</div>
</div>
<div class="container">
@yield('main')
</div> </div>
@endsection @endsection

68
resources/views/beers/create.blade.php

@ -0,0 +1,68 @@
@extends('beers')
@section('main')
<div class="row">
<div class="col-sm-8 offset-sm-2">
<h1 class="display-3">Add a Beer</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('beers.store') }}">
@csrf
<div class="form-group">
<label for="name">Name</label>
<input type="text" class="form-control" name="name">
</div>
<div class="form-group">
<label for="keywords">Keywords</label>
<textarea type="text" class="form-control" name="keywords" ></textarea>
</div>
<div class="Type">
<label for="type">Style</label>
<input type="text" class="form-control" name="type">
</div>
<div class="form-group">
<label for="abv">ABV %</label>
<input type="text" class="form-control" name="abv">
</div>
<div class="form-group">
<label for="og">Original Gravity (OG)</label>
<input type="text" class="form-control" name="og">
</div>
<div class="form-group">
<label for="fg">Final Gravity (FG)</label>
<input type="text" class="form-control" name="fg">
</div>
<div class="form-group">
<label for="source">Source</label>
<input type="text" class="form-control" name="source">
</div>
<div class="form-group">
<label for="notes">Notes</label>
<textarea type="text" class="form-control" name="notes"></textarea>
</div>
<div class="form-group">
<label for="brewery_id">Brewery ID</label>
<input type="text" class="form-control" name="brewery_id">
</div>
<div class="form-group">
<label for="batch">Batch Size (L)</label>
<input type="text" class="form-control" name="batch">
</div>
<div class="form-group">
<label for="mine">Mine?</label>
<input type="checkbox" class="form-control" name="mine" checked>
</div>
<button type="submit" class="btn btn-primary">Add brewery</button>
</form>
</div>
</div>
</div>
@endsection

67
resources/views/beers/edit.blade.php

@ -0,0 +1,67 @@
@extends('beers')
@section('main') <div class="row">
<div class="col-sm-8 offset-sm-2">
<h1 class="display-3">Update Beer</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('beers.update', $beer->beer_id) }}">
@method('PATCH')
@csrf
<div class="form-group">
<label for="name">Name</label>
<input type="text" class="form-control" name="name" value={{ $beer->name }} />>
</div>
<div class="form-group">
<label for="keywords">Keywords</label>
<textarea type="text" class="form-control" name="keywords" value={{ $beer->keywords }} /> ></textarea>
</div>
<div class="Type">
<label for="type">Style</label>
<input type="text" class="form-control" name="type" value={{ $beer->type }} />>
</div>
<div class="form-group">
<label for="abv">ABV %</label>
<input type="text" class="form-control" name="abv" value={{ $beer->abv }} />>
</div>
<div class="form-group">
<label for="og">Original Gravity (OG)</label>
<input type="text" class="form-control" name="og" value={{ $beer->og }} />>
</div>
<div class="form-group">
<label for="fg">Final Gravity (FG)</label>
<input type="text" class="form-control" name="fg" value={{ $beer->fg }} />>
</div>
<div class="form-group">
<label for="source">Source</label>
<input type="text" class="form-control" name="source" value={{ $beer->source }} />>
</div>
<div class="form-group">
<label for="notes">Notes</label>
<textarea type="text" class="form-control" name="notes" value={{ $beer->notes }} />></textarea>
</div>
<div class="form-group">
<label for="brewery_id">Brewery ID</label>
<input type="text" class="form-control" name="brewery_id" value={{ $beer->brewery_id }} />>
</div>
<div class="form-group">
<label for="batch">Batch Size (L)</label>
<input type="text" class="form-control" name="batch" value={{ $beer->batch }} />>
</div>
<div class="form-group">
<label for="mine">Mine?</label>
<input type="checkbox" class="form-control" name="mine" value={{ $beer->mine }} />>
</div>
<button type="submit" class="btn btn-primary">Update</button>
</form>
</div>
</div>
@endsection

55
resources/views/beers/index.blade.php

@ -0,0 +1,55 @@
@extends('beers')
@section('main')
<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> -> {{ __('Beer List') }}<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 Beer
</button>
<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">Name</th>
<th scope="col">Brewery</th>
<th scope="col">Style</th>
@if (Auth::user()->isAdmin())<th colspan="2" scope="col">Admin</th>@endif
</tr>
</thead>
<tbody>
@foreach ($beers as $beer)
<tr>
<td><a href="/beer/{{$beer->beer_id}}">{{$beer->name}}</a> </td>
<td><a href="/brewery/{{$beer->brewery_id}}">{{$beer->brewery}}</a> </td>
<td>{{$beer->type}} </td>
@if (Auth::user()->isAdmin())
<td><a href="{{ route('beers.edit',$beer->beer_id)}}" class="btn btn-primary">Edit</a></td>
<td><form action="{{ route('beers.destroy', $beer->beer_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

0
resources/views/summaries/create.blade.php

0
resources/views/summaries/edit.blade.php

0
resources/views/summaries/index.blade.php

8
routes/web.php

@ -23,13 +23,13 @@ Route::any('/register', function() {
}); });
Route::resource('breweries', 'App\Http\Controllers\BrewerieController'); Route::resource('breweries', 'App\Http\Controllers\BrewerieController');
Route::resource('beers', 'App\Http\Controllers\SummarieController');
Route::get('/home', [App\Http\Controllers\SummarieController::class, 'index'])->name('home'); Route::get('/home', [App\Http\Controllers\SummarieController::class, 'index'])->name('home');
Route::get('/adjuncts', [App\Http\Controllers\AdjunctController::class, 'index'])->name('adjuncts'); Route::get('/adjuncts', [App\Http\Controllers\AdjunctController::class, 'index'])->name('adjuncts');
Route::get('/grains', [App\Http\Controllers\GrainController::class, 'index'])->name('grains'); Route::get('/grains', [App\Http\Controllers\GrainController::class, 'index'])->name('grains');
Route::get('/hops', [App\Http\Controllers\HopController::class, 'index'])->name('hops'); Route::get('/hops', [App\Http\Controllers\HopController::class, 'index'])->name('hops');
Route::get('/yeasts', [App\Http\Controllers\YeastController::class, 'index'])->name('yeasts'); Route::get('/yeasts', [App\Http\Controllers\YeastController::class, 'index'])->name('yeasts');
//Route::get('/breweries', [App\Http\Controllers\BrewerieController::class, 'index'])->name('breweries');
Route::get('/beers', [App\Http\Controllers\SummarieController::class, 'index'])->name('beers');
//Route::get('/beers', [App\Http\Controllers\SummarieController::class, 'index'])->name('beers');
Route::get('/fermentations', [App\Http\Controllers\FermentationController::class, 'index'])->name('fermentations'); Route::get('/fermentations', [App\Http\Controllers\FermentationController::class, 'index'])->name('fermentations');
Route::get('/grainbills', [App\Http\Controllers\GrainbillController::class, 'index'])->name('grainbills'); Route::get('/grainbills', [App\Http\Controllers\GrainbillController::class, 'index'])->name('grainbills');
Route::get('/mashes', [App\Http\Controllers\MasheController::class, 'index'])->name('mashes'); Route::get('/mashes', [App\Http\Controllers\MasheController::class, 'index'])->name('mashes');
@ -45,11 +45,9 @@ Route::post('/grains', [App\Http\Controllers\GrainController::class, 'store'])->
Route::post('/hops', [App\Http\Controllers\HopController::class, 'store'])->name('hops.store'); Route::post('/hops', [App\Http\Controllers\HopController::class, 'store'])->name('hops.store');
Route::post('/yeasts', [App\Http\Controllers\YeastController::class, 'store'])->name('yeasts.store'); Route::post('/yeasts', [App\Http\Controllers\YeastController::class, 'store'])->name('yeasts.store');
Route::post('/adjuncts', [App\Http\Controllers\AdjunctController::class, 'store'])->name('adjuncts.store'); Route::post('/adjuncts', [App\Http\Controllers\AdjunctController::class, 'store'])->name('adjuncts.store');
//Route::post('/breweries', [App\Http\Controllers\BrewerieController::class, 'store'])->name('breweries.store');
Route::post('/beers', [App\Http\Controllers\SummarieController::class, 'store'])->name('beers.store');
//Route::post('/beers', [App\Http\Controllers\SummarieController::class, 'store'])->name('beers.store');
Route::post('/grainbills', [App\Http\Controllers\GrainbillController::class, 'store'])->name('grainbills.store'); Route::post('/grainbills', [App\Http\Controllers\GrainbillController::class, 'store'])->name('grainbills.store');
Route::post('/mashes', [App\Http\Controllers\MasheController::class, 'store'])->name('mash.store'); 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('/hopadditions', [App\Http\Controllers\HopAdditionController::class, 'store'])->name('hopadditions.store');
Route::post('/adjunctadditions', [App\Http\Controllers\AdjunctAdditionController::class, 'store'])->name('adjunctadditions.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'); Route::post('/fermentations', [App\Http\Controllers\FermentationController::class, 'store'])->name('fermentations.store');
//Route::get('/breweries/{id}/edit', [App\Http\Controllers\BrewerieController::class, 'edit'])->name('breweries.edit');
Loading…
Cancel
Save