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.

94 lines
2.9 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. <?php
  2. namespace App\Http\Controllers;
  3. use Illuminate\Http\Request;
  4. use App\Models\Fermentation;
  5. use App\Models\Yeast;
  6. use App\Models\Summarie;
  7. class FermentationController extends Controller
  8. {
  9. public function __construct()
  10. {
  11. $this->middleware('auth');
  12. }
  13. public function index()
  14. {
  15. $fermentations = Fermentation::get();
  16. foreach ($fermentations as $fermentation)
  17. {
  18. $beername = Summarie::where('beer_id', $fermentation->beer_id)->value('name');
  19. $yeastname = Yeast::where('id', $fermentation->yeast_id)->value('name');
  20. $fermentation['beer'] = $beername;
  21. $fermentation['name'] = $yeastname;
  22. }
  23. return view('fermentations.index')->with('fermentations', $fermentations);
  24. }
  25. public function store(Request $request){
  26. // validation
  27. $this->validate($request,[
  28. 'beer_id' => 'required',
  29. 'yeast_id' => 'required',
  30. 'temperature' => 'required',
  31. 'duration' => 'required',
  32. ]);
  33. // create project
  34. $yeast = new Fermentation;
  35. $lastID = Fermentation::orderBy('id','desc')->take(1)->value('id');
  36. $yeast->id = number_format($lastID) + 1;
  37. $yeast->beer_id = $request->input('beer_id');
  38. $yeast->yeast_id = $request->input('yeast_id');
  39. $yeast->temperature = $request->input('temperature');
  40. $yeast->duration = $request->input('duration');
  41. if ($request->input('alternative'))
  42. {
  43. $yeast->alternative = $request->input('alternative');
  44. }
  45. $yeast->save();
  46. return redirect('/fermentations')->with('success', 'Fermentation Step Added');
  47. }
  48. public function edit($id){
  49. $fermentation = Fermentation::where('id', (int)$id)->first();
  50. return view('fermentations.edit')->with('fermentation', $fermentation);
  51. }
  52. public function update(Request $request, $id){
  53. // validation
  54. $this->validate($request,[
  55. 'beer_id' => 'required',
  56. 'yeast_id' => 'required',
  57. 'temperature' => 'required',
  58. 'duration' => 'required',
  59. ]);
  60. $yeast = Fermentation::where('id', (int)$id)->first();
  61. $yeast->beer_id = $request->input('beer_id');
  62. $yeast->yeast_id = $request->input('yeast_id');
  63. $yeast->temperature = $request->input('temperature');
  64. $yeast->duration = $request->input('duration');
  65. if ($request->input('alternative'))
  66. {
  67. $yeast->alternative = $request->input('alternative');
  68. }
  69. $yeast->save();
  70. return redirect('/fermentations')->with('success', 'Fermentation Step Updated!');
  71. }
  72. public function create()
  73. {
  74. return view('fermentations.create');
  75. }
  76. public function destroy($id)
  77. {
  78. $fermentation = Fermentation::find($id);
  79. $fermentation->delete();
  80. return redirect('/fermentations')->with('success', 'Fermentation Step deleted!');
  81. }
  82. }