123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- <?php
- namespace think\model;
- use think\Collection as BaseCollection;
- use think\Model;
- class Collection extends BaseCollection
- {
-
- public function load($relation)
- {
- if (!$this->isEmpty()) {
- $item = current($this->items);
- $item->eagerlyResultSet($this->items, $relation);
- }
- return $this;
- }
-
- public function bindAttr($relation, array $attrs = [])
- {
- $this->each(function (Model $model) use ($relation, $attrs) {
- $model->bindAttr($relation, $attrs);
- });
- return $this;
- }
-
- public function hidden($hidden = [], $override = false)
- {
- $this->each(function ($model) use ($hidden, $override) {
-
- $model->hidden($hidden, $override);
- });
- return $this;
- }
-
- public function visible($visible = [], $override = false)
- {
- $this->each(function ($model) use ($visible, $override) {
-
- $model->visible($visible, $override);
- });
- return $this;
- }
-
- public function append($append = [], $override = false)
- {
- $this->each(function ($model) use ($append, $override) {
-
- $model && $model->append($append, $override);
- });
- return $this;
- }
-
- public function withAttr($name, $callback = null)
- {
- $this->each(function ($model) use ($name, $callback) {
-
- $model && $model->withAttribute($name, $callback);
- });
- return $this;
- }
- }
|