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.

141 lines
4.0 KiB

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\Hop;
  5. class HopController extends Controller
  6. {
  7. public function __construct()
  8. {
  9. $this->middleware('auth');
  10. }
  11. public function index()
  12. {
  13. $project = Hop::orderBy('name')->get();
  14. return view('hops.index')->with('hops', $project);
  15. }
  16. public function store(Request $request){
  17. // validation
  18. $this->validate($request,[
  19. 'name' => 'required',
  20. ]);
  21. // create project
  22. $hop = new hop;
  23. $lastID = Hop::orderBy('id','desc')->take(1)->value('id');
  24. $hop->id = number_format($lastID) + 1;
  25. $hop->name = $request->input('name');
  26. if ($request->input('alpha_acid'))
  27. {
  28. $hop->alpha_acid = $request->input('alpha_acid');
  29. }
  30. $hop->bitter = $request->input('bitter');
  31. $hop->aroma = $request->input('aroma');
  32. if ($request->input('beta_acid'))
  33. {
  34. $hop->beta_acid = $request->input('beta_acid');
  35. }
  36. if ($request->input('myrcene'))
  37. {
  38. $hop->myrcene = $request->input('myrcene');
  39. }
  40. if ($request->input('profile'))
  41. {
  42. $hop->profile = '{'.$request->input('profile').'}';
  43. }
  44. if ($request->input('humulene'))
  45. {
  46. $hop->humulene = $request->input('humulene');
  47. }
  48. if ($request->input('total_oil'))
  49. {
  50. $hop->total_oil = $request->input('total_oil');
  51. }
  52. if ($request->input('cohumulone'))
  53. {
  54. $hop->cohumulone = $request->input('cohumulone');
  55. }
  56. if ($request->input('farnesene'))
  57. {
  58. $hop->farnesene = $request->input('farnesene');
  59. }
  60. if ($request->input('caryophyllene'))
  61. {
  62. $hop->caryophyllene = $request->input('caryophyllene');
  63. }
  64. $hop->save();
  65. return redirect('/hops')->with('success', 'Hop Added!');
  66. }
  67. public function edit($id){
  68. $hop = Hop::where('id', (int)$id)->first();
  69. return view('hops.edit')->with('hop', $hop);
  70. }
  71. public function update(Request $request, $id){
  72. // validation
  73. $this->validate($request,[
  74. 'name' => 'required',
  75. ]);
  76. $hop = Hop::where('id', (int)$id)->first();
  77. $hop->name = $request->input('name');
  78. if ($request->input('alpha_acid'))
  79. {
  80. $hop->alpha_acid = $request->input('alpha_acid');
  81. }
  82. $hop->bitter = $request->input('bitter');
  83. $hop->aroma = $request->input('aroma');
  84. if ($request->input('beta_acid'))
  85. {
  86. $hop->beta_acid = $request->input('beta_acid');
  87. }
  88. if ($request->input('myrcene'))
  89. {
  90. $hop->myrcene = $request->input('myrcene');
  91. }
  92. if ($request->input('profile'))
  93. {
  94. $hop->profile = '{'.$request->input('profile').'}';
  95. }
  96. if ($request->input('humulene'))
  97. {
  98. $hop->humulene = $request->input('humulene');
  99. }
  100. if ($request->input('total_oil'))
  101. {
  102. $hop->total_oil = $request->input('total_oil');
  103. }
  104. if ($request->input('cohumulone'))
  105. {
  106. $hop->cohumulone = $request->input('cohumulone');
  107. }
  108. if ($request->input('farnesene'))
  109. {
  110. $hop->farnesene = $request->input('farnesene');
  111. }
  112. if ($request->input('caryophyllene'))
  113. {
  114. $hop->caryophyllene = $request->input('caryophyllene');
  115. }
  116. $hop->save();
  117. return redirect('/hops')->with('success', 'Hop Updated!');
  118. }
  119. public function create()
  120. {
  121. return view('hops.create');
  122. }
  123. public function destroy($id)
  124. {
  125. $hop = Hop::find($id);
  126. $hop->delete();
  127. return redirect('/hops')->with('success', 'Hop deleted!');
  128. }
  129. }