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'); } }