|
|
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request; use App\Models\Mashe; use App\Models\Summarie;
class MasheController extends Controller { public function __construct() { $this->middleware('auth'); }
public function index() { $mashes = Mashe::get(); foreach ($mashes as $mash) { $beername = Summarie::where('beer_id', $mash->beer_id)->value('name'); $mash['beer'] = $beername; } return view('mashes.index')->with('mashes', $mashes); }
public function store(Request $request){ // validation
$this->validate($request,[ 'beer_id' => 'required', 'temperature' => 'required', 'duration' => 'required', 'stage' => 'required', 'boil' => 'required', ]);
// create project
$mash = new Mashe; $lastID = Mashe::orderBy('id','desc')->take(1)->value('id'); $mash->id = number_format($lastID) + 1; $mash->beer_id = $request->input('beer_id'); $mash->temp = $request->input('temperature'); $mash->duration = $request->input('duration'); $mash->stage = $request->input('stage'); $mash->boil = $request->input('boil'); $mash->save();
return redirect('/mashes')->with('success', 'Mash Step Added!'); } public function edit($id){ $mash = Mashe::where('id', (int)$id)->first(); $beers = Summarie::orderBy('name')->get(); $selected_beer = $mash->beer_id; $data = array('mash'=>$mash, 'beers'=>$beers, 'selected_beer'=>$selected_beer); return view('mashes.edit')->with($data); }
public function update(Request $request, $id){ // validation
$this->validate($request,[ 'beer_id' => 'required', 'temperature' => 'required', 'duration' => 'required', 'stage' => 'required', 'boil' => 'required', ]);
$mash = Mashe::where('id', (int)$id)->first(); $mash->beer_id = $request->input('beer_id'); $mash->temp = $request->input('temperature'); $mash->duration = $request->input('duration'); $mash->stage = $request->input('stage'); $mash->boil = $request->input('boil'); $mash->save();
return redirect('/mashes')->with('success', 'Mash Step Updated!'); } public function create() { $beers = Summarie::orderBy('name')->get(); return view('mashes.create')->with('beers', $beers); } public function destroy($id) { $mash = Mashe::find($id); $mash->delete();
return redirect('/mashes')->with('success', 'Mash Step Deleted!'); } }
|