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.

69 lines
1.6 KiB

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