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.

91 lines
2.7 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\Mashe;
  5. use App\Models\Summarie;
  6. class MasheController extends Controller
  7. {
  8. public function __construct()
  9. {
  10. $this->middleware('auth');
  11. }
  12. public function index()
  13. {
  14. $mashes = Mashe::get();
  15. foreach ($mashes as $mash)
  16. {
  17. $beername = Summarie::where('beer_id', $mash->beer_id)->value('name');
  18. $mash['beer'] = $beername;
  19. }
  20. return view('mashes.index')->with('mashes', $mashes);
  21. }
  22. public function store(Request $request){
  23. // validation
  24. $this->validate($request,[
  25. 'beer_id' => 'required',
  26. 'temperature' => 'required',
  27. 'duration' => 'required',
  28. 'stage' => 'required',
  29. 'boil' => 'required',
  30. ]);
  31. // create project
  32. $mash = new Mashe;
  33. $lastID = Mashe::orderBy('id','desc')->take(1)->value('id');
  34. $mash->id = number_format($lastID) + 1;
  35. $mash->beer_id = $request->input('beer_id');
  36. $mash->temp = $request->input('temperature');
  37. $mash->duration = $request->input('duration');
  38. $mash->stage = $request->input('stage');
  39. $mash->boil = $request->input('boil');
  40. $mash->save();
  41. return redirect('/mashes')->with('success', 'Mash Step Added!');
  42. }
  43. public function edit($id){
  44. $mash = Mashe::where('id', (int)$id)->first();
  45. $beers = Summarie::orderBy('name')->get();
  46. $selected_beer = $mash->beer_id;
  47. $data = array('mash'=>$mash, 'beers'=>$beers, 'selected_beer'=>$selected_beer);
  48. return view('mashes.edit')->with($data);
  49. }
  50. public function update(Request $request, $id){
  51. // validation
  52. $this->validate($request,[
  53. 'beer_id' => 'required',
  54. 'temperature' => 'required',
  55. 'duration' => 'required',
  56. 'stage' => 'required',
  57. 'boil' => 'required',
  58. ]);
  59. $mash = Mashe::where('id', (int)$id)->first();
  60. $mash->beer_id = $request->input('beer_id');
  61. $mash->temp = $request->input('temperature');
  62. $mash->duration = $request->input('duration');
  63. $mash->stage = $request->input('stage');
  64. $mash->boil = $request->input('boil');
  65. $mash->save();
  66. return redirect('/mashes')->with('success', 'Mash Step Updated!');
  67. }
  68. public function create()
  69. {
  70. $beers = Summarie::orderBy('name')->get();
  71. return view('mashes.create')->with('beers', $beers);
  72. }
  73. public function destroy($id)
  74. {
  75. $mash = Mashe::find($id);
  76. $mash->delete();
  77. return redirect('/mashes')->with('success', 'Mash Step Deleted!');
  78. }
  79. }