12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- <?php
- namespace think\model;
- use think\Collection as BaseCollection;
- use think\Model;
- class Collection extends BaseCollection
- {
-
- * 返回数组中指定的一列
- * @param string $column_key
- * @param string|null $index_key
- * @return array
- */
- public function column($column_key, $index_key = null)
- {
- if (function_exists('array_column')) {
- return array_column($this->toArray(), $column_key, $index_key);
- }
- return parent::column($column_key, $index_key);
- }
-
- * 延迟预载入关联查询
- * @access public
- * @param mixed $relation 关联
- * @return $this
- */
- public function load($relation)
- {
- $item = current($this->items);
- $item->eagerlyResultSet($this->items, $relation);
- return $this;
- }
-
- * 设置需要隐藏的输出属性
- * @access public
- * @param array $hidden 属性列表
- * @param bool $override 是否覆盖
- * @return $this
- */
- public function hidden($hidden = [], $override = false)
- {
- $this->each(function ($model) use ($hidden, $override) {
-
- $model->hidden($hidden, $override);
- });
- return $this;
- }
-
- * 设置需要输出的属性
- * @param array $visible
- * @param bool $override 是否覆盖
- * @return $this
- */
- public function visible($visible = [], $override = false)
- {
- $this->each(function ($model) use ($visible, $override) {
-
- $model->visible($visible, $override);
- });
- return $this;
- }
-
- * 设置需要追加的输出属性
- * @access public
- * @param array $append 属性列表
- * @param bool $override 是否覆盖
- * @return $this
- */
- public function append($append = [], $override = false)
- {
- $this->each(function ($model) use ($append, $override) {
-
- $model->append($append, $override);
- });
- return $this;
- }
- }
|