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.

44 lines
1.1 KiB

3 years ago
  1. <?php
  2. namespace App\Http\Controllers;
  3. use Illuminate\Http\Request;
  4. use App\Models\Hopaddition;
  5. class HopAdditionController extends Controller
  6. {
  7. public function __construct()
  8. {
  9. $this->middleware('auth');
  10. }
  11. public function index()
  12. {
  13. $project = Hopaddition::orderBy('id')->get();
  14. return view('hopadditions')->with('hopadditions', $project);
  15. }
  16. public function store(Request $request){
  17. // validation
  18. $this->validate($request,[
  19. 'beer_id' => 'required',
  20. 'hop_id' => 'required',
  21. 'amount' => 'required',
  22. 'timing' => 'required',
  23. ]);
  24. // create project
  25. $hop = new Hopaddition;
  26. $lastID = Hopaddition::orderBy('id','desc')->value('id');
  27. $hop->id = number_format($lastID) + 1;
  28. $hop->beer_id = $request->input('beer_id');
  29. $hop->hop_id = $request->input('hop_id');
  30. $hop->amount = $request->input('amount');
  31. $hop->timing = $request->input('timing');
  32. $hop->save();
  33. return redirect('/hopadditions')->with('success', 'Hop Addition Added');
  34. }
  35. }