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.

88 lines
2.5 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. return view('mashes.edit')->with('mash', $mash);
  46. }
  47. public function update(Request $request, $id){
  48. // validation
  49. $this->validate($request,[
  50. 'beer_id' => 'required',
  51. 'temperature' => 'required',
  52. 'duration' => 'required',
  53. 'stage' => 'required',
  54. 'boil' => 'required',
  55. ]);
  56. $mash = Mashe::where('id', (int)$id)->first();
  57. $mash->beer_id = $request->input('beer_id');
  58. $mash->temp = $request->input('temperature');
  59. $mash->duration = $request->input('duration');
  60. $mash->stage = $request->input('stage');
  61. $mash->boil = $request->input('boil');
  62. $mash->save();
  63. return redirect('/mashes')->with('success', 'Mash Step Updated!');
  64. }
  65. public function create()
  66. {
  67. $beers = Summarie::orderBy('name')->get();
  68. return view('mashes.create')->with('beers', $beers);
  69. }
  70. public function destroy($id)
  71. {
  72. $mash = Mashe::find($id);
  73. $mash->delete();
  74. return redirect('/mashes')->with('success', 'Mash Step Deleted!');
  75. }
  76. }