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.

77 lines
1.8 KiB

3 years ago
  1. <?php
  2. namespace App\Http\Controllers;
  3. use Illuminate\Http\Request;
  4. use App\Models\Grainbill;
  5. class EditController extends Controller
  6. {
  7. /**
  8. * Create a new controller instance.
  9. *
  10. * @return void
  11. */
  12. public function __construct()
  13. {
  14. $this->middleware('auth');
  15. }
  16. /**
  17. * Show the application dashboard.
  18. *
  19. * @return \Illuminate\Contracts\Support\Renderable
  20. */
  21. public function index()
  22. {
  23. return view('edit');
  24. }
  25. public function gstore(Request $request){
  26. // validation
  27. $this->validate($request,[
  28. 'name' => 'required',
  29. ]);
  30. // create project
  31. $grain = new Grainbill;
  32. $lastID = Grainbill::orderBy('id','desc')->value('id');
  33. $grain->id = number_format($lastID) + 1;
  34. $grain->name = $request->input('name');
  35. if ($request->input('flavour'))
  36. {
  37. $grain->flavour = $request->input('flavour');
  38. }
  39. if ($request->input('lintner'))
  40. {
  41. $grain->lintner = $request->input('lintner');
  42. }
  43. if ($request->input('winkol'))
  44. {
  45. $grain->winkol = $request->input('winkol');
  46. }
  47. if ($request->input('lovibond'))
  48. {
  49. $grain->lovibond = $request->input('lovibond');
  50. }
  51. if ($request->input('colour'))
  52. {
  53. $grain->colour = $request->input('colour');
  54. }
  55. if ($request->input('alternative'))
  56. {
  57. $altArr = array_map('intval',explode(',',$request->input('alternative')));
  58. $grain->alternative = $altArr;
  59. }
  60. if ($request->input('ebc'))
  61. {
  62. $grain->ebc = $request->input('ebc');
  63. }
  64. $grain->save();
  65. return redirect('/edit')->with('success', 'Grain Bill Added');
  66. }
  67. }