BannerGroup.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. use App\Models\DTO\SearchData;
  5. class BannerGroup extends Model
  6. {
  7. protected $table = 'tb_banner_group';
  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. protected $guarded = [];
  15. public function user()
  16. {
  17. return $this->belongsTo(User::class)->withDefault();
  18. }
  19. public function banner()
  20. {
  21. return $this->hasMany(Banner::class);
  22. }
  23. /**
  24. * 배너 그룹 조회
  25. */
  26. public function data(SearchData $params): object
  27. {
  28. $query = $this->query();
  29. $query->select('*');
  30. $list = $query->paginate($params->perPage, ['*'], 'page', $params->page);
  31. $total = $this->count();
  32. $rows = $list->count();
  33. return (object)[
  34. 'total' => $total,
  35. 'list' => $list,
  36. 'rows' => $rows
  37. ];
  38. }
  39. }