Browse Source

adjuncts refactor mkI

master
jk 3 years ago
parent
commit
da97973679
  1. 33
      app/Http/Controllers/AdjunctController.php
  2. 56
      resources/views/adjuncts.blade.php
  3. 28
      resources/views/adjuncts/create.blade.php
  4. 27
      resources/views/adjuncts/edit.blade.php
  5. 41
      resources/views/adjuncts/index.blade.php
  6. 5
      routes/web.php

33
app/Http/Controllers/AdjunctController.php

@ -16,7 +16,7 @@ class AdjunctController extends Controller
public function index()
{
$adjuncts = Adjunct::orderBy('name')->get();
return view('adjuncts')->with('adjuncts', $adjuncts);
return view('adjuncts.index')->with('adjuncts', $adjuncts);
}
public function store(Request $request){
@ -28,14 +28,41 @@ class AdjunctController extends Controller
// create project
$adjunct = new Adjunct;
$lastID = Adjunct::orderBy('id','desc')->value('id');
$lastID = Adjunct::orderBy('id','desc')->take(1)->value('id');
$adjunct->id = number_format($lastID) + 1;
$adjunct->name = $request->input('name');
$adjunct->save();
return redirect('/adjuncts')->with('success', 'Adjunct Added');
return redirect('/adjuncts')->with('success', 'Adjunct Added!');
}
public function edit($id){
$adjunct = Adjunct::where('id', (int)$id)->first();
return view('adjuncts.edit')->with('adjunct', $adjunct);
}
public function update(Request $request, $id){
// validation
$this->validate($request,[
'name' => 'required',
]);
$adjunct = Adjunct::where('id', (int)$id)->first();
$adjunct->name = $request->input('name');
$adjunct->save();
return redirect('/adjuncts')->with('success', 'Adjunct Updated!');
}
public function create()
{
return view('adjuncts.create');
}
public function destroy($id)
{
$adjunct = Adjunct::find($id);
$adjunct->delete();
return redirect('/adjuncts')->with('success', 'Adjunct deleted!');
}
}

56
resources/views/adjuncts.blade.php

@ -1,60 +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 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 Adjunct
</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')
<tbody>
@foreach ($adjuncts as $adjunct)
<tr>
<td><a href="/adjunct/{{$adjunct->id}}">{{$adjunct->name}}</a> </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 Adjunct</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('adjuncts.store')}}" method="post">
{{csrf_field()}}
<div class="form-group">
<label for="">Name</label>
<input type="text" class="form-control" name="name">
</div>
<input type="submit" name="submit" value="Submit" class="btn btn-success">
</form>
</div>
</div>
</div>
<div class="container">
@yield('main')
</div>
@endsection

28
resources/views/adjuncts/create.blade.php

@ -0,0 +1,28 @@
@extends('adjuncts')
@section('main')
<div class="row">
<div class="col-sm-8 offset-sm-2">
<h1 class="display-3">Add an Adjunct</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('adjuncts.store') }}">
@csrf
<div class="form-group">
<label for="">Name</label>
<input type="text" class="form-control" name="name">
</div>
<button type="submit" class="btn btn-primary">Add Adjunct</button>
</form>
</div>
</div>
</div>
@endsection

27
resources/views/adjuncts/edit.blade.php

@ -0,0 +1,27 @@
@extends('adjuncts')
@section('main') <div class="row">
<div class="col-sm-8 offset-sm-2">
<h1 class="display-3">Update Adjunct</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('adjuncts.update', $adjunct->id) }}">
@method('PATCH')
@csrf
<div class="form-group">
<label for="name">Name</label>
<input type="text" class="form-control" name="name" value="{{$adjunct->name}}" />
</div>
<button type="submit" class="btn btn-primary">Update</button>
</form>
</div>
</div>
@endsection

41
resources/views/adjuncts/index.blade.php

@ -0,0 +1,41 @@
@extends('adjuncts')
@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> -> {{ __('Adjunct List') }}<span class="backlink"><a href="{{url()->previous()}}">Go Back</a></span></div>
<div class="card-body">
@if (Auth::user()->isAdmin())
<a href="{{ route('adjuncts.create') }}" class="btn btn-primary">Add Grain</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')
<tbody>
@foreach ($adjuncts as $adjunct)
<tr>
<td><a href="/adjunct/{{$adjunct->id}}">{{$adjunct->name}}</a> </td>
@if (Auth::user()->isAdmin())
<td><a href="{{ route('adjuncts.edit',$adjunct->id)}}" class="btn btn-primary">Edit</a></td>
<td><form action="{{ route('adjuncts.destroy', $adjunct->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

5
routes/web.php

@ -27,9 +27,8 @@ Route::resource('beers', 'App\Http\Controllers\SummarieController');
Route::resource('grains', 'App\Http\Controllers\GrainController');
Route::resource('hops', 'App\Http\Controllers\HopController');
Route::resource('yeasts', 'App\Http\Controllers\YeastController');
Route::resource('adjuncts', 'App\Http\Controllers\AdjunctController');
Route::get('/home', [App\Http\Controllers\SummarieController::class, 'index'])->name('home');
Route::get('/adjuncts', [App\Http\Controllers\AdjunctController::class, 'index'])->name('adjuncts');
//Route::get('/yeasts', [App\Http\Controllers\YeastController::class, 'index'])->name('yeasts');
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');
@ -41,8 +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('/yeasts', [App\Http\Controllers\YeastController::class, 'store'])->name('yeasts.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('/mashes', [App\Http\Controllers\MasheController::class, 'store'])->name('mash.store');
Route::post('/hopadditions', [App\Http\Controllers\HopAdditionController::class, 'store'])->name('hopadditions.store');

Loading…
Cancel
Save