LinkController.php 2.8 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\Http\Requests\Backend\Link\CreateRequest;
  7. use App\Http\Requests\Backend\Link\UpdateRequest;
  8. use App\Repositories\LinkRepositoryEloquent;
  9. class LinkController extends Controller
  10. {
  11. protected $link;
  12. public function __construct(LinkRepositoryEloquent $link)
  13. {
  14. $this->link = $link;
  15. }
  16. /**
  17. * Display a listing of the resource.
  18. *
  19. * @return \Illuminate\Http\Response
  20. */
  21. public function index()
  22. {
  23. $links = $this->link->all();
  24. return view('backend.link.index', compact('links'));
  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.link.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->link->create($request->all())) {
  44. return redirect('backend/link')->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. $link = $this->link->find($id);
  67. return view('backend.link.edit', compact('link'));
  68. }
  69. /**
  70. * Update the specified resource in storage.
  71. *
  72. * @param \Illuminate\Http\Request $request
  73. * @param int $id
  74. * @return \Illuminate\Http\Response
  75. */
  76. public function update(UpdateRequest $request, $id)
  77. {
  78. $link = $this->link->find($id);
  79. if ($link) {
  80. if ($this->link->update($request->all(), $id)) {
  81. return redirect('backend/link')->with('success', '友情链接添加成功');
  82. }
  83. }
  84. return redirect()->back()->withErrors('系统异常,修改友情链接失败');
  85. }
  86. /**
  87. * Remove the specified resource from storage.
  88. *
  89. * @param int $id
  90. * @return \Illuminate\Http\Response
  91. */
  92. public function destroy($id)
  93. {
  94. if ($this->link->find($id)) {
  95. if ($this->link->delete($id)) {
  96. return response()->json(['status' => 0]);
  97. }
  98. }
  99. return response()->json(['status' => 1]);
  100. }
  101. }