PostController.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. namespace App\Http\Controllers\Admin\Board\Trash;
  3. use Illuminate\Http\Request;
  4. use App\Http\Controllers\Controller;
  5. use App\Http\Traits\AgentTrait;
  6. use App\Models\Board;
  7. use App\Models\PostDeleted;
  8. use App\Models\DTO\SearchData;
  9. class PostController extends Controller
  10. {
  11. use AgentTrait;
  12. private Board $boardModel;
  13. private PostDeleted $postDeletedModel;
  14. public function __construct(Board $board, PostDeleted $postDeleted)
  15. {
  16. $this->boardModel = $board;
  17. $this->postDeletedModel = $postDeleted;
  18. }
  19. /**
  20. * 게시판 > 휴지통 관리 (게시글)
  21. * @method GET
  22. * @see /admin/board/trash/post
  23. */
  24. public function index(Request $request)
  25. {
  26. $params = SearchData::fromRequest($request);
  27. $params->boardID = $request->get('board_id');
  28. $postDeletedData = $this->postDeletedModel->data($params);
  29. if ($postDeletedData->rows > 0) {
  30. $num = listNum($postDeletedData->total, $params->page, $params->perPage);
  31. foreach ($postDeletedData->list as $i => $row) {
  32. $row->num = $num--;
  33. $row->editURL = route('admin.board.trash.post.edit', $row->id);
  34. $postDeletedData->list[$i] = $row;
  35. }
  36. }
  37. return view('admin.board.trash.post.index', [
  38. 'postDeletedData' => $postDeletedData,
  39. 'params' => $params,
  40. 'boardData' => $this->boardModel->all()
  41. ]);
  42. }
  43. /**
  44. * 게시판 > 휴지통 관리(게시글) > 전체삭제
  45. * @method GET
  46. * @see /admin/board/trash/post/truncate
  47. */
  48. public function truncate()
  49. {
  50. if(!$this->postDeletedModel->truncate()) {
  51. return back()->withErrors("휴지통 전체 삭제에 실패하였습니다.")->withInput();
  52. }
  53. $message = '휴지통에 게시글을 전체 삭제하였습니다.';
  54. return redirect()->route('admin.board.trash.post.index')->with('message', $message);
  55. }
  56. /**
  57. * 게시판 > 휴지통 관리(게시글) > 선택삭제
  58. * @method GET
  59. * @see /admin/board/trash/post/destroy
  60. */
  61. public function destroy(Request $request)
  62. {
  63. $chk = $request->post('chk');
  64. if ($chk) {
  65. foreach ($chk as $deletedID) {
  66. if(!$this->postDeletedModel->remove($deletedID)) {
  67. return back()->withErrors($deletedID . "번 게시글을 삭제할 수 없습니다.")->withInput();
  68. }
  69. }
  70. }
  71. $message = '게시글이 삭제되었습니다.';
  72. return redirect()->route('admin.board.trash.post.index')->with('message', $message);
  73. }
  74. /**
  75. * 게시판 > 휴지통 관리(게시글) > 복원하기
  76. * @method POST
  77. * @see /admin/board/trash/post/recovery
  78. */
  79. public function recovery(Request $request)
  80. {
  81. $chk = $request->post('chk');
  82. if ($chk) {
  83. foreach ($chk as $deletedID) {
  84. if(!$this->postDeletedModel->recovery($deletedID)) {
  85. return back()->withErrors($deletedID . "번 게시글을 복원할 수 없습니다.")->withInput();
  86. }
  87. }
  88. }
  89. $message = '게시글이 복원되었습니다.';
  90. return redirect()->route('admin.board.trash.post.index')->with('message', $message);
  91. }
  92. /**
  93. * 게시판 > 휴지통 관리(게시글) > 상세보기
  94. * @method GET
  95. * @see /admin/board/trash/post/{pk}/edit
  96. */
  97. public function edit(int $deletedID)
  98. {
  99. $deleted = $this->postDeletedModel->findOrFail($deletedID);
  100. $deleted->device = $this->device($deleted->user_agent);
  101. $deleted->platform = $this->platform($deleted->user_agent);
  102. $deleted->browser = $this->browser($deleted->user_agent);
  103. return view('admin.board.trash.post.edit', [
  104. 'deleted' => $deleted
  105. ]);
  106. }
  107. }