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.

46 lines
1.1 KiB

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