HistoryController.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace App\Http\Controllers\Admin\Sms;
  3. use Illuminate\Http\Request;
  4. use App\Http\Controllers\Controller;
  5. use App\Models\SmsHistory;
  6. use App\Models\DTO\SearchData;
  7. class HistoryController extends Controller
  8. {
  9. private SmsHistory $smsHistoryModel;
  10. public function __construct(SmsHistory $smsHistory)
  11. {
  12. $this->smsHistoryModel = $smsHistory;
  13. }
  14. /**
  15. * SMS > 전송 내역
  16. * @method GET
  17. * @see /admin/sms/history
  18. */
  19. public function index(Request $request)
  20. {
  21. $params = SearchData::fromRequest($request);
  22. $smsHistoryData = $this->smsHistoryModel->data($params);
  23. if ($smsHistoryData->rows > 0) {
  24. $num = listNum($smsHistoryData->total, $params->page, $params->perPage);
  25. foreach ($smsHistoryData->list as $i => $row) {
  26. $row->num = $num--;
  27. $row->isReserveStr = ($row->is_reserve ? 'Y' : 'N');
  28. $row->reserveAt = dateBr($row->reserve_at, '-');
  29. $row->createdAt = dateBr($row->created_at);
  30. $smsHistoryData->list[$i] = $row;
  31. }
  32. }
  33. return view('admin.sms.history.index', [
  34. 'smsHistoryData' => $smsHistoryData,
  35. 'params' => $params
  36. ]);
  37. }
  38. /**
  39. * 전송내역 삭제
  40. * @method DELETE
  41. * @see /admin/sms/history
  42. */
  43. public function destroy(Request $request)
  44. {
  45. $chk = $request->post('chk');
  46. if ($chk) {
  47. foreach ($chk as $historyID) {
  48. $this->smsHistoryModel->find($historyID)->delete();
  49. }
  50. }
  51. $message = '전송 내역이 삭제되었습니다.';
  52. return redirect()->route('admin.sms.history.index')->with('message', $message);
  53. }
  54. }