My beer compendium
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.

48 lines
1.3 KiB

3 years ago
  1. <?php
  2. namespace App\Http\Controllers;
  3. use Illuminate\Http\Request;
  4. use App\Models\Fermentation;
  5. class FermentationController extends Controller
  6. {
  7. public function __construct()
  8. {
  9. $this->middleware('auth');
  10. }
  11. public function index()
  12. {
  13. $project = Fermentation::get();
  14. return view('fermentations')->with('fermentations', $project);
  15. }
  16. public function store(Request $request){
  17. // validation
  18. $this->validate($request,[
  19. 'beer_id' => 'required',
  20. 'yeast_id' => 'required',
  21. 'temperature' => 'required',
  22. 'duration' => 'required',
  23. ]);
  24. // create project
  25. $yeast = new Fermentations;
  26. $lastID = Fermentations::orderBy('id','desc')->value('id');
  27. $yeast->id = number_format($lastID) + 1;
  28. $yeast->beer_id = $request->input('beer_id');
  29. $yeast->yeast_id = $request->input('yeast_id');
  30. $yeast->temperature = $request->input('temperature');
  31. $yeast->duration = $request->input('duration');
  32. if ($request->input('alternative'))
  33. {
  34. $yeast->alternative = $request->input('alternative');
  35. }
  36. $yeast->save();
  37. return redirect('/fermnentations')->with('success', 'Fermentation Step Added');
  38. }
  39. }