UsefulLinkController.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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($request->all());
  46. return redirect()->route('admin.usefullinks.index')->with('success', __('link has been created!'));
  47. }
  48. /**
  49. * Display the specified resource.
  50. *
  51. * @param UsefulLink $usefullink
  52. * @return Response
  53. */
  54. public function show(UsefulLink $usefullink)
  55. {
  56. //
  57. }
  58. /**
  59. * Show the form for editing the specified resource.
  60. *
  61. * @param UsefulLink $usefullink
  62. * @return Application|Factory|View
  63. */
  64. public function edit(UsefulLink $usefullink)
  65. {
  66. return view('admin.usefullinks.edit' , [
  67. 'link' => $usefullink
  68. ]);
  69. }
  70. /**
  71. * Update the specified resource in storage.
  72. *
  73. * @param Request $request
  74. * @param UsefulLink $usefullink
  75. * @return RedirectResponse
  76. */
  77. public function update(Request $request, UsefulLink $usefullink)
  78. {
  79. $request->validate([
  80. 'icon' => 'required|string',
  81. 'title' => 'required|string|max:60',
  82. 'link' => 'required|url|string|max:191',
  83. 'description' => 'required|string|max:2000',
  84. ]);
  85. $usefullink->update($request->all());
  86. return redirect()->route('admin.usefullinks.index')->with('success', __('link has been updated!'));
  87. }
  88. /**
  89. * Remove the specified resource from storage.
  90. *
  91. * @param UsefulLink $usefullink
  92. * @return Response
  93. */
  94. public function destroy(UsefulLink $usefullink)
  95. {
  96. $usefullink->delete();
  97. return redirect()->back()->with('success', __('product has been removed!'));
  98. }
  99. public function dataTable()
  100. {
  101. $query = UsefulLink::query();
  102. return datatables($query)
  103. ->addColumn('actions', function (UsefulLink $link) {
  104. return '
  105. <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>
  106. <form class="d-inline" onsubmit="return submitResult();" method="post" action="' . route('admin.usefullinks.destroy', $link->id) . '">
  107. ' . csrf_field() . '
  108. ' . method_field("DELETE") . '
  109. <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>
  110. </form>
  111. ';
  112. })
  113. ->editColumn('created_at', function (UsefulLink $link) {
  114. return $link->created_at ? $link->created_at->diffForHumans() : '';
  115. })
  116. ->editColumn('icon', function (UsefulLink $link) {
  117. return "<i class='{$link->icon}'></i>";
  118. })
  119. ->rawColumns(['actions' , 'icon'])
  120. ->make();
  121. }
  122. }