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.
|
|
<?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(); return view('mashes.edit')->with('mash', $mash); }
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() { return view('mashes.create'); } public function destroy($id) { $mash = Mashe::find($id); $mash->delete();
return redirect('/mashes')->with('success', 'Mash Step Deleted!'); } }
|