NavigationController.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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->orderBy('sequence', 'desc')->all();
  24. return view('backend.navigation.index', compact('navigations'));
  25. }
  26. /**
  27. * Show the form for creating a new resource.
  28. *
  29. * @return \Illuminate\Http\Response
  30. */
  31. public function create()
  32. {
  33. return view('backend.navigation.create');
  34. }
  35. /**
  36. * Store a newly created resource in storage.
  37. *
  38. * @param \Illuminate\Http\Request $request
  39. * @return \Illuminate\Http\Response
  40. */
  41. public function store(CreateRequest $request)
  42. {
  43. if ($this->navigation->create($request->all())) {
  44. return redirect('backend/navigation')->with('success', '导航添加成功');
  45. }
  46. return redirect()->back()->withErrors('系统异常,导航添加失败');
  47. }
  48. /**
  49. * Display the specified resource.
  50. *
  51. * @param int $id
  52. * @return \Illuminate\Http\Response
  53. */
  54. public function show($id)
  55. {
  56. //
  57. }
  58. /**
  59. * Show the form for editing the specified resource.
  60. *
  61. * @param int $id
  62. * @return \Illuminate\Http\Response
  63. */
  64. public function edit($id)
  65. {
  66. $navigation = $this->navigation->find($id);
  67. if ($navigation) {
  68. return view('backend.navigation.edit', compact('navigation'));
  69. }
  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. $navigation = $this->navigation->find($id);
  94. if ($navigation) {
  95. if ($this->navigation->delete($id)) {
  96. return response()->json(['status' => 0]);
  97. }
  98. }
  99. return response()->json(['status' => 1]);
  100. }
  101. }