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.

68 lines
1.6 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. <?php
  2. namespace App\Http\Controllers;
  3. use Illuminate\Http\Request;
  4. use App\Models\Adjunct;
  5. class AdjunctController extends Controller
  6. {
  7. public function __construct()
  8. {
  9. $this->middleware('auth');
  10. }
  11. public function index()
  12. {
  13. $adjuncts = Adjunct::orderBy('name')->get();
  14. return view('adjuncts.index')->with('adjuncts', $adjuncts);
  15. }
  16. public function store(Request $request){
  17. // validation
  18. $this->validate($request,[
  19. 'name' => 'required',
  20. ]);
  21. // create project
  22. $adjunct = new Adjunct;
  23. $lastID = Adjunct::orderBy('id','desc')->take(1)->value('id');
  24. $adjunct->id = number_format($lastID) + 1;
  25. $adjunct->name = $request->input('name');
  26. $adjunct->save();
  27. return redirect('/adjuncts')->with('success', 'Adjunct Added!');
  28. }
  29. public function edit($id){
  30. $adjunct = Adjunct::where('id', (int)$id)->first();
  31. return view('adjuncts.edit')->with('adjunct', $adjunct);
  32. }
  33. public function update(Request $request, $id){
  34. // validation
  35. $this->validate($request,[
  36. 'name' => 'required',
  37. ]);
  38. $adjunct = Adjunct::where('id', (int)$id)->first();
  39. $adjunct->name = $request->input('name');
  40. $adjunct->save();
  41. return redirect('/adjuncts')->with('success', 'Adjunct Updated!');
  42. }
  43. public function create()
  44. {
  45. return view('adjuncts.create');
  46. }
  47. public function destroy($id)
  48. {
  49. $adjunct = Adjunct::find($id);
  50. $adjunct->delete();
  51. return redirect('/adjuncts')->with('success', 'Adjunct deleted!');
  52. }
  53. }