diff --git a/app/Http/Controllers/SummarieController.php b/app/Http/Controllers/SummarieController.php
index 4b7e2dc..4b4c54d 100644
--- a/app/Http/Controllers/SummarieController.php
+++ b/app/Http/Controllers/SummarieController.php
@@ -17,55 +17,116 @@ class SummarieController extends Controller
public function index()
{
$beers = Summarie::orderBy('name')->get();
- foreach ($beers as $beer)
- {
- $brewery = DB::table('breweries')->where('id', $beer->brewery_id)->value('name');
- $beer['brewery'] = $brewery;
- }
- return view('beers')->with('summaries', $beers);
+ foreach ($beers as $beer)
+ {
+ $beer = DB::table('breweries')->where('id', $beer->beer_id)->value('name');
+ $beer['beer'] = $beer;
+ }
+ return view('beers.index')->with('beers', $beers);
}
- public function store(Request $request){
+ public function store(Request $request){
// validation
$this->validate($request,[
'name' => 'required',
- 'type' => 'required',
- 'abv' => 'required',
- 'fg' => 'required',
- 'keywords' => 'required',
- 'og' => 'required',
- 'source' => 'required',
- 'batch' => 'required',
- 'brewery_id' => 'required'
+ 'type' => 'required',
+ 'abv' => 'required',
+ 'fg' => 'required',
+ 'keywords' => 'required',
+ 'og' => 'required',
+ 'source' => 'required',
+ 'batch' => 'required',
+ 'beer_id' => 'required',
+ 'brewery_id' => 'required'
]);
// create project
- $beers = new Summarie;
+ $beer = new Summarie;
$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)
- {
- $beers->mine = true;
- } else {
- $beers->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->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('brewery_id');
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');
}
+ 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!');
+ }
+
+
+
}
diff --git a/resources/views/beers.blade.php b/resources/views/beers.blade.php
index 82b2baa..9ede88a 100644
--- a/resources/views/beers.blade.php
+++ b/resources/views/beers.blade.php
@@ -1,110 +1,8 @@
@extends('layouts.app')
@section('content')
-
-
+
+@yield('main')
-
-
@endsection
diff --git a/resources/views/beers/create.blade.php b/resources/views/beers/create.blade.php
new file mode 100644
index 0000000..6013897
--- /dev/null
+++ b/resources/views/beers/create.blade.php
@@ -0,0 +1,68 @@
+@extends('beers')
+
+@section('main')
+
+@endsection
diff --git a/resources/views/beers/edit.blade.php b/resources/views/beers/edit.blade.php
new file mode 100644
index 0000000..77e58f2
--- /dev/null
+++ b/resources/views/beers/edit.blade.php
@@ -0,0 +1,67 @@
+@extends('beers')
+@section('main')
+@endsection
diff --git a/resources/views/beers/index.blade.php b/resources/views/beers/index.blade.php
new file mode 100644
index 0000000..1874503
--- /dev/null
+++ b/resources/views/beers/index.blade.php
@@ -0,0 +1,55 @@
+@extends('beers')
+
+@section('main')
+
+
+
+
+@include('inc.navbar')
+
+
+
+@if (Auth::user()->isAdmin())
+
+
+@endif
+
+
+ @include('inc.messages')
+
+
+ Name |
+ Brewery |
+ Style |
+ @if (Auth::user()->isAdmin())Admin | @endif
+
+
+
+
+ @foreach ($beers as $beer)
+
+ {{$beer->name}} |
+ {{$beer->brewery}} |
+ {{$beer->type}} |
+ @if (Auth::user()->isAdmin())
+Edit |
+ |
+@endif
+
+
+ @endforeach
+
+
+
+
+
+
+
+
+@endsection
diff --git a/resources/views/summaries/create.blade.php b/resources/views/summaries/create.blade.php
deleted file mode 100644
index e69de29..0000000
diff --git a/resources/views/summaries/edit.blade.php b/resources/views/summaries/edit.blade.php
deleted file mode 100644
index e69de29..0000000
diff --git a/resources/views/summaries/index.blade.php b/resources/views/summaries/index.blade.php
deleted file mode 100644
index e69de29..0000000
diff --git a/routes/web.php b/routes/web.php
index efaba75..2e4e647 100644
--- a/routes/web.php
+++ b/routes/web.php
@@ -23,13 +23,13 @@ Route::any('/register', function() {
});
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('/adjuncts', [App\Http\Controllers\AdjunctController::class, 'index'])->name('adjuncts');
Route::get('/grains', [App\Http\Controllers\GrainController::class, 'index'])->name('grains');
Route::get('/hops', [App\Http\Controllers\HopController::class, 'index'])->name('hops');
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('/grainbills', [App\Http\Controllers\GrainbillController::class, 'index'])->name('grainbills');
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('/yeasts', [App\Http\Controllers\YeastController::class, 'store'])->name('yeasts.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('/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');
-//Route::get('/breweries/{id}/edit', [App\Http\Controllers\BrewerieController::class, 'edit'])->name('breweries.edit');