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.

79 lines
2.0 KiB

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')->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')->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. }