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.
 
 
 
 
 
 

69 lines
1.6 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')->with('grains', $grains);
}
public function store(Request $request){
// validation
$this->validate($request,[
'name' => 'required',
]);
// create project
$grain = new Grain;
$lastID = Grain::orderBy('id','desc')->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'))
{
$altArr = array_map('intval',explode(',',$request->input('alternative')));
$grain->alternative = $altArr;
}
if ($request->input('ebc'))
{
$grain->ebc = $request->input('ebc');
}
$grain->save();
return redirect('/grains')->with('success', 'Grain Added');
}
}