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.

96 lines
3.3 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. return view('adjunctadditions.edit')->with('adjunctaddition', $adjunctaddition);
  51. }
  52. public function update(Request $request, $id){
  53. // validation
  54. $this->validate($request,[
  55. 'beer_id' => 'required',
  56. 'adjunct_id' => 'required',
  57. 'amount' => 'required',
  58. 'timing' => 'required',
  59. ]);
  60. $adjunct = Adjunctaddition::where('id', (int)$id)->first();
  61. $adjunct->beer_id = $request->input('beer_id');
  62. $adjunct->adjunct_id = $request->input('adjunct_id');
  63. $adjunct->amount = $request->input('amount');
  64. $adjunct->timing = $request->input('timing');
  65. $adjunct->alternative = $request->input('alternative');
  66. $adjunct->notes = $request->input('notes');
  67. $adjunct->save();
  68. return redirect('/adjunctadditions')->with('success', 'Adjunct Addition Updated!');
  69. }
  70. public function create()
  71. {
  72. $beers = Summarie::orderBy('name')->get();
  73. $adjuncts = Adjunct::orderBy('name')->get();
  74. $data = array('beers'=>$beers, 'adjuncts'=>$adjuncts);
  75. return view('adjunctadditions.create')->with($data);
  76. }
  77. public function destroy($id)
  78. {
  79. $adjunctaddition = Adjunctaddition::find($id);
  80. $adjunctaddition->delete();
  81. return redirect('/adjunctadditions')->with('success', 'Adjunct Addition deleted!');
  82. }
  83. }