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.

102 lines
3.8 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\Adjunctaddition;
  5. use App\Models\Adjunct;
  6. use App\Models\Summarie;
  7. class AdjunctAdditionController extends Controller
  8. {
  9. public function __construct()
  10. {
  11. $this->middleware('auth');
  12. }
  13. public function index()
  14. {
  15. $adjunctadditions = Adjunctaddition::get();
  16. foreach ($adjunctadditions as $adjunctaddition)
  17. {
  18. $beername = Summarie::where('beer_id', $adjunctaddition->beer_id)->value('name');
  19. $adjunctname = Adjunct::where('id', $adjunctaddition->adjunct_id)->value('name');
  20. $altname = Adjunct::where('id', $adjunctaddition->alternative)->value('name');
  21. $adjunctaddition['beer'] = $beername;
  22. $adjunctaddition['name'] = $adjunctname;
  23. $adjunctaddition['alternativename'] = $altname;
  24. }
  25. return view('adjunctadditions.index')->with('adjunctadditions', $adjunctadditions);
  26. }
  27. public function store(Request $request){
  28. // validation
  29. $this->validate($request,[
  30. 'beer_id' => 'required',
  31. 'adjunct_id' => 'required',
  32. 'amount' => 'required',
  33. 'timing' => 'required',
  34. ]);
  35. // create project
  36. $adjunct = new Adjunctaddition;
  37. $lastID = Adjunctaddition::orderBy('id','desc')->take(1)->value('id');
  38. $adjunct->id = number_format($lastID) + 1;
  39. $adjunct->beer_id = $request->input('beer_id');
  40. $adjunct->adjunct_id = $request->input('adjunct_id');
  41. $adjunct->amount = $request->input('amount');
  42. $adjunct->timing = $request->input('timing');
  43. $adjunct->alternative = $request->input('alternative');
  44. $adjunct->notes = $request->input('notes');
  45. $adjunct->save();
  46. return redirect('/adjunctadditions')->with('success', 'Adjunct Addition Added');
  47. }
  48. public function edit($id){
  49. $adjunctaddition = Adjunctaddition::where('id', (int)$id)->first();
  50. $beers = Summarie::orderBy('name')->get();
  51. $selected_beer = $adjunctaddition->beer_id;
  52. $adjuncts = Adjunct::orderBy('name')->get();
  53. $selected_adjunct = $adjunctaddition->adjunct_id;
  54. $selected_alt = $adjunctaddition->alternative;
  55. $data = array('adjunctaddition'=>$adjunctaddition, 'beers'=>$beers, 'adjuncts'=>$adjuncts, 'selected_beer'=>$selected_beer, 'selected_adjunct'=>$selected_adjunct, 'selected_alt'=>$selected_alt);
  56. return view('adjunctadditions.edit')->with($data);
  57. }
  58. public function update(Request $request, $id){
  59. // validation
  60. $this->validate($request,[
  61. 'beer_id' => 'required',
  62. 'adjunct_id' => 'required',
  63. 'amount' => 'required',
  64. 'timing' => 'required',
  65. ]);
  66. $adjunct = Adjunctaddition::where('id', (int)$id)->first();
  67. $adjunct->beer_id = $request->input('beer_id');
  68. $adjunct->adjunct_id = $request->input('adjunct_id');
  69. $adjunct->amount = $request->input('amount');
  70. $adjunct->timing = $request->input('timing');
  71. $adjunct->alternative = $request->input('alternative');
  72. $adjunct->notes = $request->input('notes');
  73. $adjunct->save();
  74. return redirect('/adjunctadditions')->with('success', 'Adjunct Addition Updated!');
  75. }
  76. public function create()
  77. {
  78. $beers = Summarie::orderBy('name')->get();
  79. $adjuncts = Adjunct::orderBy('name')->get();
  80. $data = array('beers'=>$beers, 'adjuncts'=>$adjuncts);
  81. return view('adjunctadditions.create')->with($data);
  82. }
  83. public function destroy($id)
  84. {
  85. $adjunctaddition = Adjunctaddition::find($id);
  86. $adjunctaddition->delete();
  87. return redirect('/adjunctadditions')->with('success', 'Adjunct Addition deleted!');
  88. }
  89. }