Browse Source

yeasts refactor mkI

master
jk 3 years ago
parent
commit
e257c28faf
  1. 54
      app/Http/Controllers/YeastController.php
  2. 83
      resources/views/yeasts.blade.php
  3. 48
      resources/views/yeasts/create.blade.php
  4. 47
      resources/views/yeasts/edit.blade.php
  5. 49
      resources/views/yeasts/index.blade.php
  6. 7
      routes/web.php

54
app/Http/Controllers/YeastController.php

@ -15,7 +15,7 @@ class YeastController extends Controller
public function index() public function index()
{ {
$yeasts = Yeast::orderBy('name')->get(); $yeasts = Yeast::orderBy('name')->get();
return view('yeasts')->with('yeasts', $yeasts);
return view('yeasts.index')->with('yeasts', $yeasts);
} }
public function store(Request $request){ public function store(Request $request){
@ -27,7 +27,7 @@ class YeastController extends Controller
// create project // create project
$yeast = new Yeast; $yeast = new Yeast;
$lastID = Yeast::orderBy('id','desc')->value('id');
$lastID = Yeast::orderBy('id','desc')->take(1)->value('id');
$yeast->id = number_format($lastID) + 1; $yeast->id = number_format($lastID) + 1;
$yeast->name = $request->input('name'); $yeast->name = $request->input('name');
if ($request->input('attenuation')) if ($request->input('attenuation'))
@ -52,6 +52,54 @@ class YeastController extends Controller
} }
$yeast->save(); $yeast->save();
return redirect('/yeasts')->with('success', 'Yeast Added');
return redirect('/yeasts')->with('success', 'Yeast Added!');
}
public function edit($id){
$grain = Grain::where('id', (int)$id)->first();
return view('grains.edit')->with('grain', $grain);
}
public function update(Request $request, $id){
// validation
$this->validate($request,[
'name' => 'required',
]);
$yeast = Yeast::where('id', (int)$id)->first();
$yeast->name = $request->input('name');
if ($request->input('attenuation'))
{
$yeast->attenuation = $request->input('attenuation');
}
if ($request->input('flocculation'))
{
$yeast->flocculation = $request->input('flocculation');
}
if ($request->input('profile'))
{
$yeast->profile = '{'.$request->input('profile').'}';
}
if ($request->input('tolerance'))
{
$yeast->tolerance = $request->input('tolerance');
}
if ($request->input('temp_range'))
{
$yeast->temp_range = $request->input('temp_range');
}
$yeast->save();
return redirect('/yeasts')->with('success', 'Yeast Updated!');
}
public function create()
{
return view('yeasts.create');
}
public function destroy($id)
{
$yeast = Yeast::find($id);
$yeast->delete();
return redirect('/yeasts')->with('success', 'Yeast deleted!');
} }
} }

83
resources/views/yeasts.blade.php

@ -1,87 +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> -> {{ __('Yeast 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 Yeast
</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">Profile</th>
</tr>
</thead>
<tbody>
@foreach ($yeasts as $yeast)
<tr>
<td><a href="/yeast/{{$yeast->id}}">{{$yeast->name}}</a> </td>
<td>{{str_replace(' ,',',',str_replace('"',' ',str_replace(',',', ',str_replace('}', '', str_replace('{','',$yeast->profile)))))}} </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 yeast</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('yeasts.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="">Profile</label>
<textarea type="text" class="form-control" name="profile" ></textarea>
</div>
<div class="form-group">
<label for="">Attenuation</label>
<input type="text" class="form-control" name="attenuation">
</div>
<div class="form-group">
<label for="">Flocculation</label>
<input type="text" class="form-control" name="flocculation">
</div>
<div class="form-group">
<label for="">Alcohol Tolerance</label>
<input type="text" class="form-control" name="tolerance">
</div>
<div class="form-group">
<label for="">Temperature Range °C</label>
<input type="text" class="form-control" name="temp_range">
</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

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

@ -0,0 +1,48 @@
@extends('yeasts')
@section('main')
<div class="row">
<div class="col-sm-8 offset-sm-2">
<h1 class="display-3">Add a Yeast</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('yeasts.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="profile">Profile</label>
<textarea type="text" class="form-control" name="profile" ></textarea>
</div>
<div class="form-group">
<label for="attenuation">Attenuation</label>
<input type="text" class="form-control" name="attenuation">
</div>
<div class="form-group">
<label for="flocculation">Flocculation</label>
<input type="text" class="form-control" name="flocculation">
</div>
<div class="form-group">
<label for="tolerance">Alcohol Tolerance</label>
<input type="text" class="form-control" name="tolerance">
</div>
<div class="form-group">
<label for="temp_range">Temperature Range °C</label>
<input type="text" class="form-control" name="temp_range">
</div>
<button type="submit" class="btn btn-primary">Add Yeast</button>
</form>
</div>
</div>
</div>
@endsection

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

@ -0,0 +1,47 @@
@extends('yeasts')
@section('main') <div class="row">
<div class="col-sm-8 offset-sm-2">
<h1 class="display-3">Update Yeast</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('yeasts.update', $yeast->id) }}">
@method('PATCH')
@csrf
<div class="form-group">
<label for="name">Name</label>
<input type="text" class="form-control" name="name" value="{{$yeast->name}}" />
</div>
<div class="form-group">
<label for="profile">Profile</label>
<textarea type="text" class="form-control" name="profile" >{{$yeast->profile}}</textarea>
</div>
<div class="form-group">
<label for="attenuation">Attenuation</label>
<input type="text" class="form-control" name="attenuation" value="{{$yeast->attenuation}}" />
</div>
<div class="form-group">
<label for="flocculation">Flocculation</label>
<input type="text" class="form-control" name="flocculation" value="{{$yeast->flocculation}}" />
</div>
<div class="form-group">
<label for="tolerance">Alcohol Tolerance</label>
<input type="text" class="form-control" name="tolerance" value="{{$yeast->tolerance}}" />
</div>
<div class="form-group">
<label for="temp_range">Temperature Range °C</label>
<input type="text" class="form-control" name="temp_range" value="{{$yeast->temp_range}}" />
</div>
<button type="submit" class="btn btn-primary">Update</button>
</form>
</div>
</div>
@endsection

49
resources/views/yeasts/index.blade.php

@ -0,0 +1,49 @@
@extends('yeasts')
@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> -> {{ __('Yeast List') }}<span class="backlink"><a href="{{url()->previous()}}">Go Back</a></span></div>
<div class="card-body">
@if (Auth::user()->isAdmin())
<a href="{{ route('yeasts.create') }}" class="btn btn-primary">Add Yeast</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">Name</th>
<th scope="col">Profile</th>
@if (Auth::user()->isAdmin())<th colspan="2" scope="col">Admin</th>@endif
</tr>
</thead>
<tbody>
@foreach ($yeasts as $yeast)
<tr>
<td><a href="/yeast/{{$yeast->id}}">{{$yeast->name}}</a> </td>
<td>{{str_replace(' ,',',',str_replace('"',' ',str_replace(',',', ',str_replace('}', '', str_replace('{','',$yeast->profile)))))}} </td>
@if (Auth::user()->isAdmin())
<td><a href="{{ route('yeasts.edit',$yeast->id)}}" class="btn btn-primary">Edit</a></td>
<td><form action="{{ route('yeasts.destroy', $yeast->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

7
routes/web.php

@ -26,10 +26,10 @@ Route::resource('breweries', 'App\Http\Controllers\BrewerieController');
Route::resource('beers', 'App\Http\Controllers\SummarieController'); Route::resource('beers', 'App\Http\Controllers\SummarieController');
Route::resource('grains', 'App\Http\Controllers\GrainController'); Route::resource('grains', 'App\Http\Controllers\GrainController');
Route::resource('hops', 'App\Http\Controllers\HopController'); Route::resource('hops', 'App\Http\Controllers\HopController');
Route::resource('yeasts', 'App\Http\Controllers\YeastController');
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('/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('/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');
@ -41,8 +41,7 @@ Route::get('/grain/{grainID}', [App\Http\Controllers\GraincardController::class,
Route::get('/yeast/{yeastID}', [App\Http\Controllers\YeastcardController::class, 'index'])->name('yeast'); 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('/hop/{hopID}', [App\Http\Controllers\HopcardController::class, 'index'])->name('hop');
Route::get('/adjunct/{adjunctID}', [App\Http\Controllers\AdjunctcardController::class, 'index'])->name('adjunct'); Route::get('/adjunct/{adjunctID}', [App\Http\Controllers\AdjunctcardController::class, 'index'])->name('adjunct');
//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('/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');

Loading…
Cancel
Save