SmsFavorite.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. use App\Models\DTO\SearchData;
  5. class SmsFavorite extends Model
  6. {
  7. protected $table = 'tb_sms_favorite';
  8. protected $primaryKey = 'id';
  9. public $keyType = 'int';
  10. public $incrementing = true;
  11. public $timestamps = true;
  12. const CREATED_AT = 'created_at';
  13. const UPDATED_AT = 'updated_at';
  14. const DELETED_AT = null;
  15. protected $guarded = [];
  16. /**
  17. * 자주보내는 문자 조회
  18. */
  19. public function data(SearchData $params): object
  20. {
  21. $query = $this->query();
  22. $query->select('tb_sms_favorite.*');
  23. if($params->keyword) {
  24. switch ($params->field) {
  25. case 'tb_sms_favorite.id' :
  26. $query->where($params->field, '=', $params->keyword);
  27. break;
  28. case 'tb_sms_favorite.subject' :
  29. case 'tb_sms_favorite.content' :
  30. $query->where($params->field, 'LIKE', "%{$params->keyword}%");
  31. break;
  32. }
  33. }
  34. $query->orderByDesc('tb_sms_favorite.id');
  35. $list = $query->paginate($params->perPage, ['*'], 'page', $params->page);
  36. $total = $this->count();
  37. $rows = $list->count();
  38. return (object)[
  39. 'total' => $total,
  40. 'rows' => $rows,
  41. 'list' => $list
  42. ];
  43. }
  44. }