You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

80 lines
2.3 KiB

  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkPHP [ WE CAN DO IT JUST THINK ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +----------------------------------------------------------------------
  9. // | Author: zhangyajun <448901948@qq.com>
  10. // +----------------------------------------------------------------------
  11. namespace think\model;
  12. use think\Collection as BaseCollection;
  13. use think\Model;
  14. class Collection extends BaseCollection
  15. {
  16. /**
  17. * 延迟预载入关联查询
  18. * @access public
  19. * @param mixed $relation 关联
  20. * @return $this
  21. */
  22. public function load($relation)
  23. {
  24. $item = current($this->items);
  25. $item->eagerlyResultSet($this->items, $relation);
  26. return $this;
  27. }
  28. /**
  29. * 设置需要隐藏的输出属性
  30. * @access public
  31. * @param array $hidden 属性列表
  32. * @param bool $override 是否覆盖
  33. * @return $this
  34. */
  35. public function hidden($hidden = [], $override = false)
  36. {
  37. $this->each(function ($model) use ($hidden, $override) {
  38. /** @var Model $model */
  39. $model->hidden($hidden, $override);
  40. });
  41. return $this;
  42. }
  43. /**
  44. * 设置需要输出的属性
  45. * @param array $visible
  46. * @param bool $override 是否覆盖
  47. * @return $this
  48. */
  49. public function visible($visible = [], $override = false)
  50. {
  51. $this->each(function ($model) use ($visible, $override) {
  52. /** @var Model $model */
  53. $model->visible($visible, $override);
  54. });
  55. return $this;
  56. }
  57. /**
  58. * 设置需要追加的输出属性
  59. * @access public
  60. * @param array $append 属性列表
  61. * @param bool $override 是否覆盖
  62. * @return $this
  63. */
  64. public function append($append = [], $override = false)
  65. {
  66. $this->each(function ($model) use ($append, $override) {
  67. /** @var Model $model */
  68. $model && $model->append($append, $override);
  69. });
  70. return $this;
  71. }
  72. }