My beer compendium
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

123 lines
3.2 KiB

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Grain;
use Illuminate\Support\Facades\DB;
class GrainController extends Controller
{
public function __construct()
{
$this->middleware('auth');
}
public function index()
{
$grains = Grain::orderBy('name')->get();
return view('grains.index')->with('grains', $grains);
}
public function store(Request $request){
// validation
$this->validate($request,[
'name' => 'required',
]);
// create project
$grain = new Grain;
$lastID = Grain::orderBy('id','desc')->take(1)->value('id');
$grain->id = number_format($lastID) + 1;
$grain->name = $request->input('name');
if ($request->input('flavour'))
{
$grain->flavour = $request->input('flavour');
}
if ($request->input('lintner'))
{
$grain->lintner = $request->input('lintner');
}
if ($request->input('winkol'))
{
$grain->winkol = $request->input('winkol');
}
if ($request->input('lovibond'))
{
$grain->lovibond = $request->input('lovibond');
}
if ($request->input('colour'))
{
$grain->colour = $request->input('colour');
}
if ($request->input('alternative'))
{
$grain->alternative = '{'.$request->input('alternative').'}';
}
if ($request->input('ebc'))
{
$grain->ebc = $request->input('ebc');
}
$grain->save();
return redirect('/grains')->with('success', 'Grain 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',
]);
$grain = Grain::where('id', (int)$id)->first();
$grain->name = $request->input('name');
if ($request->input('flavour'))
{
$grain->flavour = $request->input('flavour');
}
if ($request->input('lintner'))
{
$grain->lintner = $request->input('lintner');
}
if ($request->input('winkol'))
{
$grain->winkol = $request->input('winkol');
}
if ($request->input('lovibond'))
{
$grain->lovibond = $request->input('lovibond');
}
if ($request->input('colour'))
{
$grain->colour = $request->input('colour');
}
if ($request->input('alternative'))
{
$grain->alternative = '{'.$request->input('alternative').'}';
}
if ($request->input('ebc'))
{
$grain->ebc = $request->input('ebc');
}
$grain->save();
return redirect('/grains')->with('success', 'Grain Updated!');
}
public function create()
{
return view('grains.create');
}
public function destroy($id)
{
$grain = Grain::find($id);
$grain->delete();
return redirect('/grains')->with('success', 'Grain deleted!');
}
}