UsefulLinkController.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <?php
  2. namespace App\Http\Controllers\Admin;
  3. use App\Http\Controllers\Controller;
  4. use App\Models\UsefulLink;
  5. use Illuminate\Contracts\Foundation\Application;
  6. use Illuminate\Contracts\View\Factory;
  7. use Illuminate\Contracts\View\View;
  8. use Illuminate\Http\RedirectResponse;
  9. use Illuminate\Http\Request;
  10. use Illuminate\Http\Response;
  11. class UsefulLinkController extends Controller
  12. {
  13. /**
  14. * Display a listing of the resource.
  15. *
  16. * @return Application|Factory|View|Response
  17. */
  18. public function index()
  19. {
  20. return view('admin.usefullinks.index');
  21. }
  22. /**
  23. * Show the form for creating a new resource.
  24. *
  25. * @return Application|Factory|View|Response
  26. */
  27. public function create()
  28. {
  29. return view('admin.usefullinks.create');
  30. }
  31. /**
  32. * Store a newly created resource in storage.
  33. *
  34. * @param Request $request
  35. * @return RedirectResponse
  36. */
  37. public function store(Request $request)
  38. {
  39. $request->validate([
  40. 'icon' => 'required|string',
  41. 'title' => 'required|string|max:60',
  42. 'link' => 'required|url|string|max:191',
  43. 'description' => 'required|string|max:2000',
  44. ]);
  45. UsefulLink::create([
  46. 'icon' => $request->icon,
  47. 'title' => $request->title,
  48. 'link' => $request->link,
  49. 'description' => $request->description,
  50. 'navbar' => $request->navbar,
  51. ]);
  52. return redirect()->route('admin.usefullinks.index')->with('success', __('link has been created!'));
  53. }
  54. /**
  55. * Display the specified resource.
  56. *
  57. * @param UsefulLink $usefullink
  58. * @return Response
  59. */
  60. public function show(UsefulLink $usefullink)
  61. {
  62. //
  63. }
  64. /**
  65. * Show the form for editing the specified resource.
  66. *
  67. * @param UsefulLink $usefullink
  68. * @return Application|Factory|View
  69. */
  70. public function edit(UsefulLink $usefullink)
  71. {
  72. return view('admin.usefullinks.edit', [
  73. 'link' => $usefullink,
  74. ]);
  75. }
  76. /**
  77. * Update the specified resource in storage.
  78. *
  79. * @param Request $request
  80. * @param UsefulLink $usefullink
  81. * @return RedirectResponse
  82. */
  83. public function update(Request $request, UsefulLink $usefullink)
  84. {
  85. $request->validate([
  86. 'icon' => 'required|string',
  87. 'title' => 'required|string|max:60',
  88. 'link' => 'required|url|string|max:191',
  89. 'description' => 'required|string|max:2000',
  90. ]);
  91. $usefullink->update([
  92. 'icon' => $request->icon,
  93. 'title' => $request->title,
  94. 'link' => $request->link,
  95. 'description' => $request->description,
  96. 'navbar' => $request->navbar,
  97. ]);
  98. return redirect()->route('admin.usefullinks.index')->with('success', __('link has been updated!'));
  99. }
  100. /**
  101. * Remove the specified resource from storage.
  102. *
  103. * @param UsefulLink $usefullink
  104. * @return Response
  105. */
  106. public function destroy(UsefulLink $usefullink)
  107. {
  108. $usefullink->delete();
  109. return redirect()->back()->with('success', __('product has been removed!'));
  110. }
  111. public function dataTable()
  112. {
  113. $query = UsefulLink::query();
  114. return datatables($query)
  115. ->addColumn('actions', function (UsefulLink $link) {
  116. return '
  117. <a data-content="'.__('Edit').'" data-toggle="popover" data-trigger="hover" data-placement="top" href="'.route('admin.usefullinks.edit', $link->id).'" class="btn btn-sm btn-info mr-1"><i class="fas fa-pen"></i></a>
  118. <form class="d-inline" onsubmit="return submitResult();" method="post" action="'.route('admin.usefullinks.destroy', $link->id).'">
  119. '.csrf_field().'
  120. '.method_field('DELETE').'
  121. <button data-content="'.__('Delete').'" data-toggle="popover" data-trigger="hover" data-placement="top" class="btn btn-sm btn-danger mr-1"><i class="fas fa-trash"></i></button>
  122. </form>
  123. ';
  124. })
  125. ->editColumn('created_at', function (UsefulLink $link) {
  126. return $link->created_at ? $link->created_at->diffForHumans() : '';
  127. })
  128. ->editColumn('icon', function (UsefulLink $link) {
  129. return "<i class='{$link->icon}'></i>";
  130. })
  131. ->rawColumns(['actions', 'icon'])
  132. ->make();
  133. }
  134. }