1
0

NavigationController.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. namespace App\Http\Controllers\Backend;
  3. use App\Models\Navigation;
  4. use App\Http\Controllers\Controller;
  5. use App\Http\Requests\Backend\Navigation\CreateRequest;
  6. use App\Http\Requests\Backend\Navigation\UpdateRequest;
  7. class NavigationController extends Controller
  8. {
  9. /**
  10. * Display a listing of the resource.
  11. *
  12. * @return \Illuminate\Http\Response
  13. */
  14. public function index()
  15. {
  16. $navigations = Navigation::query()->with([
  17. 'category'
  18. ])->orderBy('sequence', 'desc')->get();
  19. return view('backend.navigation.index', compact('navigations'));
  20. }
  21. /**
  22. * Show the form for creating a new resource.
  23. *
  24. * @return \Illuminate\Http\Response
  25. */
  26. public function create()
  27. {
  28. return view('backend.navigation.create');
  29. }
  30. /**
  31. * Store a newly created resource in storage.
  32. *
  33. * @param CreateRequest $request
  34. * @return \Illuminate\Http\RedirectResponse
  35. */
  36. public function store(CreateRequest $request)
  37. {
  38. Navigation::create($request->all());
  39. return redirect()->route('backend.navigation.index')->with('success', '导航添加成功');
  40. }
  41. /**
  42. * Display the specified resource.
  43. *
  44. * @param int $id
  45. * @return \Illuminate\Http\Response
  46. */
  47. public function show($id)
  48. {
  49. //
  50. }
  51. /**
  52. * Show the form for editing the specified resource.
  53. *
  54. * @param int $id
  55. * @return \Illuminate\Http\Response
  56. */
  57. public function edit($id)
  58. {
  59. $navigation = Navigation::findOrFail($id);
  60. return view('backend.navigation.edit', compact('navigation'));
  61. }
  62. /**
  63. * Update the specified resource in storage.
  64. *
  65. * @param UpdateRequest $request
  66. * @param $id
  67. * @return \Illuminate\Http\RedirectResponse
  68. */
  69. public function update(UpdateRequest $request, $id)
  70. {
  71. $navigation = Navigation::findOrFail($id);
  72. $navigation->fill($request->all());
  73. $navigation->save();
  74. return redirect()->route('backend.navigation.index')->with('success', '导航修改成功');
  75. }
  76. /**
  77. * Remove the specified resource from storage.
  78. *
  79. * @param int $id
  80. * @return \Illuminate\Http\Response
  81. */
  82. public function destroy($id)
  83. {
  84. return Navigation::destroy($id) ? response()->json(['status' => 0]) : response()->json(['status' => 1]);
  85. }
  86. }