UserGroup.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. class UserGroup extends Model
  5. {
  6. protected $table = 'tb_user_group';
  7. protected $primaryKey = 'id';
  8. public $keyType = 'int';
  9. public $incrementing = true;
  10. public $timestamps = true;
  11. const CREATED_AT = 'created_at';
  12. const UPDATED_AT = 'updated_at';
  13. protected $guarded = [];
  14. public function user()
  15. {
  16. return $this->hasMany(User::class);
  17. }
  18. /**
  19. * 회원그룹 조회
  20. */
  21. public function data(): object
  22. {
  23. $query = $this->query();
  24. $query->orderBy('sort');
  25. $list = $query->get();
  26. $total = $this->count();
  27. $rows = $list->count();
  28. return (object)[
  29. 'total' => $total,
  30. 'rows' => $rows,
  31. 'list' => $list
  32. ];
  33. }
  34. /**
  35. * 전체 사용 회원그룹 조회
  36. */
  37. public function getAllGroup()
  38. {
  39. return $this->where('is_use', 1)->orderBy('sort', 'ASC')->get();
  40. }
  41. /**
  42. * 회원그룹 조회하여 배열로 반환
  43. */
  44. public function findUserGroup(int $userGroupID)
  45. {
  46. return $this->where('id', $userGroupID)->where('is_use', 1)->orderBy('sort', 'ASC')->get();
  47. }
  48. }