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.

105 lines
2.9 KiB

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\Yeast;
  5. class YeastController extends Controller
  6. {
  7. public function __construct()
  8. {
  9. $this->middleware('auth');
  10. }
  11. public function index()
  12. {
  13. $yeasts = Yeast::orderBy('name')->get();
  14. return view('yeasts.index')->with('yeasts', $yeasts);
  15. }
  16. public function store(Request $request){
  17. // validation
  18. $this->validate($request,[
  19. 'name' => 'required',
  20. ]);
  21. // create project
  22. $yeast = new Yeast;
  23. $lastID = Yeast::orderBy('id','desc')->take(1)->value('id');
  24. $yeast->id = number_format($lastID) + 1;
  25. $yeast->name = $request->input('name');
  26. if ($request->input('attenuation'))
  27. {
  28. $yeast->attenuation = $request->input('attenuation');
  29. }
  30. if ($request->input('flocculation'))
  31. {
  32. $yeast->flocculation = $request->input('flocculation');
  33. }
  34. if ($request->input('profile'))
  35. {
  36. $yeast->profile = '{'.$request->input('profile').'}';
  37. }
  38. if ($request->input('tolerance'))
  39. {
  40. $yeast->tolerance = $request->input('tolerance');
  41. }
  42. if ($request->input('temp_range'))
  43. {
  44. $yeast->temp_range = $request->input('temp_range');
  45. }
  46. $yeast->save();
  47. return redirect('/yeasts')->with('success', 'Yeast Added!');
  48. }
  49. public function edit($id){
  50. $yeast = Yeast::where('id', (int)$id)->first();
  51. return view('yeasts.edit')->with('yeast', $yeast);
  52. }
  53. public function update(Request $request, $id){
  54. // validation
  55. $this->validate($request,[
  56. 'name' => 'required',
  57. ]);
  58. $yeast = Yeast::where('id', (int)$id)->first();
  59. $yeast->name = $request->input('name');
  60. if ($request->input('attenuation'))
  61. {
  62. $yeast->attenuation = $request->input('attenuation');
  63. }
  64. if ($request->input('flocculation'))
  65. {
  66. $yeast->flocculation = $request->input('flocculation');
  67. }
  68. if ($request->input('profile'))
  69. {
  70. $yeast->profile = '{'.$request->input('profile').'}';
  71. }
  72. if ($request->input('tolerance'))
  73. {
  74. $yeast->tolerance = $request->input('tolerance');
  75. }
  76. if ($request->input('temp_range'))
  77. {
  78. $yeast->temp_range = $request->input('temp_range');
  79. }
  80. $yeast->save();
  81. return redirect('/yeasts')->with('success', 'Yeast Updated!');
  82. }
  83. public function create()
  84. {
  85. return view('yeasts.create');
  86. }
  87. public function destroy($id)
  88. {
  89. $yeast = Yeast::find($id);
  90. $yeast->delete();
  91. return redirect('/yeasts')->with('success', 'Yeast deleted!');
  92. }
  93. }