middleware('auth'); } public function index() { $project = Brewerie::orderBy('name')->get(); return view('breweries.index')->with('breweries', $project); } public function store(Request $request){ // validation $this->validate($request,[ 'name' => 'required', ]); // create project $brewerie = new Brewerie; $lastID = Brewerie::orderBy('id','desc')->value('id'); $brewerie->id = number_format($lastID) + 1; $brewerie->name = $request->input('name'); if ($request->input('place')) { $brewerie->place = $request->input('place'); } if ($request->input('country')) { $brewerie->country = $request->input('country'); } $brewerie->save(); return redirect('/breweries')->with('success', 'Brewery Added'); } public function edit($id){ $brewery = Brewerie::where('id', (int)$id)->first(); return view('breweries.edit')->with('brewery', $brewery); } public function update(Request $request, $id) { $request->validate([ 'name'=>'required', 'place'=>'required', 'country'=>'required' ]); $brewery = Brewerie::where('id', $id)->first(); $brewery->name = $request->get('name'); $brewery->place = $request->get('place'); $brewery->country = $request->get('country'); $brewery->save(); return redirect('/breweries')->with('success', 'Brewery updated!'); } public function create() { return view('breweries.create'); } public function destroy($id) { $brewery = Brewerie::find($id); $brewery->delete(); return redirect('/breweries')->with('success', 'Brewery deleted!'); } }