NavigationController.php 2.8 KB

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