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\Fermentation; use App\Models\Yeast; use App\Models\Summarie; class FermentationController extends Controller { public function __construct() { $this->middleware('auth'); }
public function index() { $fermentations = Fermentation::get(); foreach ($fermentations as $fermentation) { $beername = Summarie::where('beer_id', $fermentation->beer_id)->value('name'); $yeastname = Yeast::where('id', $fermentation->yeast_id)->value('name'); $fermentation['beer'] = $beername; $fermentation['name'] = $yeastname; } return view('fermentations.index')->with('fermentations', $fermentations); }
public function store(Request $request){ // validation
$this->validate($request,[ 'beer_id' => 'required', 'yeast_id' => 'required', 'temperature' => 'required', 'duration' => 'required', ]);
// create project
$yeast = new Fermentation; $lastID = Fermentation::orderBy('id','desc')->take(1)->value('id'); $yeast->id = number_format($lastID) + 1; $yeast->beer_id = $request->input('beer_id'); $yeast->yeast_id = $request->input('yeast_id'); $yeast->temperature = $request->input('temperature'); $yeast->duration = $request->input('duration'); if ($request->input('alternative')) { $yeast->alternative = $request->input('alternative'); } $yeast->save();
return redirect('/fermentations')->with('success', 'Fermentation Step Added'); } public function edit($id){ $fermentation = Fermentation::where('id', (int)$id)->first(); return view('fermentations.edit')->with('fermentation', $fermentation); }
public function update(Request $request, $id){ // validation
$this->validate($request,[ 'beer_id' => 'required', 'yeast_id' => 'required', 'temperature' => 'required', 'duration' => 'required', ]);
$yeast = Fermentation::where('id', (int)$id)->first(); $yeast->beer_id = $request->input('beer_id'); $yeast->yeast_id = $request->input('yeast_id'); $yeast->temperature = $request->input('temperature'); $yeast->duration = $request->input('duration'); if ($request->input('alternative')) { $yeast->alternative = $request->input('alternative'); } $yeast->save();
return redirect('/fermentations')->with('success', 'Fermentation Step Updated!'); } public function create() { return view('fermentations.create'); } public function destroy($id) { $fermentation = Fermentation::find($id); $fermentation->delete();
return redirect('/fermentations')->with('success', 'Fermentation Step deleted!'); } }
|