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.

57 lines
1.4 KiB

3 years ago
  1. <?php
  2. namespace App\Http\Controllers;
  3. use Illuminate\Http\Request;
  4. use App\Models\Yeast;
  5. class YeastController extends Controller
  6. {
  7. public function __construct()
  8. {
  9. $this->middleware('auth');
  10. }
  11. public function index()
  12. {
  13. $yeasts = Yeast::orderBy('name')->get();
  14. return view('yeasts')->with('yeasts', $yeasts);
  15. }
  16. public function store(Request $request){
  17. // validation
  18. $this->validate($request,[
  19. 'name' => 'required',
  20. ]);
  21. // create project
  22. $yeast = new Yeast;
  23. $lastID = Yeast::orderBy('id','desc')->value('id');
  24. $yeast->id = number_format($lastID) + 1;
  25. $yeast->name = $request->input('name');
  26. if ($request->input('attenuation'))
  27. {
  28. $yeast->attenuation = $request->input('attenuation');
  29. }
  30. if ($request->input('flocculation'))
  31. {
  32. $yeast->flocculation = $request->input('flocculation');
  33. }
  34. if ($request->input('profile'))
  35. {
  36. $yeast->profile = '{'.$request->input('profile').'}';
  37. }
  38. if ($request->input('tolerance'))
  39. {
  40. $yeast->tolerance = $request->input('tolerance');
  41. }
  42. if ($request->input('temp_range'))
  43. {
  44. $yeast->temp_range = $request->input('temp_range');
  45. }
  46. $yeast->save();
  47. return redirect('/yeasts')->with('success', 'Yeast Added');
  48. }
  49. }