是否是多维数组
@param $models
@return bool
518707
protected static function isSomeArr($models) {
        if (!is_array($models)) {
            return false;
        }
        $model = reset($models);
        return is_array($model) || $model instanceof Model;
    }
514393
public function update($models)
    {
        $params['body'] = [];

        $models->each(function($model) use (&$params)
        {
            $params['body'][] = [
                'update' => [
                    '_id' => $model->getKey(),
                    '_index' => $this->index,
                    '_type' => $model->searchableAs(),
                ]
            ];
            $params['body'][] = [
                'doc' => $model->toSearchableArray(),
                'doc_as_upsert' => true
            ];
        });

        $this->elastic->bulk($params);
    }
1071566
public function saveAll($models)
	{
		foreach ($models as $model)
		{
			if (!$this->associate($model)->save())
			{
				return false;
			}
		}

		return true;
	}
1005422
public function update($models)
    {
        if (! $this->shouldMaintainIndex($models->first())) {
            return;
        }

        foreach ($models as $model) {
            $this->performUpdate($model);
        }
    }
883733
protected function fetchSnippetSourceFromModels($models)
    {
        if ($this->asArray) {
            throw new InvalidCallException('"' . __METHOD__ . '" unable to determine snippet source from plain array. Either disable "asArray" option or use regular "snippetCallback"');
        }
        $result = [];
        foreach ($models as $model) {
            $result[] = $model->getSnippetSource();
        }

        return $result;
    }
702424
protected function getQueryResults(array $models) {
        if (empty($this->relations)) {
            return static::getRelationQuery($models)->all();
        }
        $data = static::getRelationQuery($models)->appendSelect($this->getRelationFields())->all();
        if (empty($data)) {
            return $data;
        }
        foreach ($this->relations as $relation) {
            if (empty($relation->getKey())) {
                return $relation->getResults($data);
            }
            $data = $relation->getResults($data);
        }
        return $data;
    }
1066799
public function setModels($models)
    {
        if (!is_object($models)) {
            if (is_array($models)) {
                $models = collect($models);
            }
        }

        if(class_basename($models->first()) == 'stdClass')
        {
            $models = $models->map(function ($array) {
                return new BlankModel($array);
            });
        }

        $this->models = $models;
    }
756016
public static function compositeGUIDs($models)
    {
        if (empty($models)) {
            return null;
        }
        if (!is_array($models) && $models instanceof static) {
            return $models->getGUID();
        }
        if (is_string($models) && strlen($models) == 16) {
            return $models;
        }
        $guids = [];
        foreach ($models as $model) {
            if ($model instanceof static) {
                $guids[] = $model->getGUID();
            } elseif (is_string($model)) {
                if (strlen($model) == 16) {
                    $guids[] = $model;
                } elseif (preg_match(Number::GUID_REGEX, $model)) {
                    $guids[] = Number::guid_bin($model);
                }
            }
        }
        return $guids;
    }
1365757
public function migrateModels($models)
    {
        // run inside callback
        $this->set(function ($c) use ($models) {
            $c->notice('Preparing to migrate models');
            $p = $c->app->db;

            foreach ($models as $model) {
                if (!is_object($model)) {
                    $model = $this->factory($model);
                    $p->add($model);
                }

                $m = new \atk4\schema\Migration\MySQL($model);
                $result = $m->migrate();

                $c->debug('  '.get_class($model).'.. '.$result);
            }

            $c->notice('Done with migration');
        });
    }
382064
private function addModelToArray($models, $model)
    {
        $apply_to_models = array();
        
        if (count($models) > 0) {
            foreach ($models as $item_json) {
                $item = json_decode($item_json);
                $object = $model->find($item->id);
                if ($object != null) {
                    for ($count = 1; $count <= $item->quantity; $count++) {
                        $apply_to_models[] = $object;
                    }
                }
            }
        }
        
        return $apply_to_models;
    }
1204910
protected function convertToAutoComplete($models)
    {
        $results = array();
        foreach( $models as $model ) {
            $results[] = array(
                'data'          => $model->id,
                'value'         => $this->getName( $model )
            );
        }

        return $results;
    }
566768
public static function create($models, array $relations) {
        $is_one = !static::isSomeArr($models);
        if ($is_one) {
            $models = [$models];
        }
        foreach ($relations as $key => $relation) {
            $relation = static::parse($relation, $key);
            $models =  $relation->getWithMulti($models);
        }
        return $is_one ? reset($models) : $models;
    }
5564
public function hasFields(array $fields)
    {
        try {
            $this->model_class::checkUnknownColumn($fields);
        } catch (UnknownColumnException $e) {
            return "Resource '$this->name' "
                . explode(' ', $e->getMessage(), 2)[1];
        }
        return true;
    }
455210
public function saveMany($models)
    {
        // Convert to collection if array
        $models = is_array($models) ? collection($models) : $models;

        foreach ($models as &$model) {
            $model = $this->save($model);
        }

        return $models;
    }
852679
protected function getFieldsFromModels($models)
    {
        if (!$models->first()) {
            // No models, we can't add any columns.
            return [];
        }

        $model = $models->first();

        // These are the Laravel basic timestamp fields which we don't want to display, by default
        $timestamp_fields = ['created_at', 'updated_at', 'deleted_at'];
        // Grab the basic fields from the first model
        $fields = array_keys($model->toArray());
        // Remove the timestamp fields
        $fields = array_diff($fields, $timestamp_fields);
        if ($model->isSortable) {
            // Add the fields from the model's sortable array
            $fields = array_unique(array_merge($fields, $model->getSortable()));
        }

        return $fields;
    }
864003
protected function getIncludedModels($models)
    {
        $links = new Collection();
        $models = $models instanceof Collection ? $models : [$models];

        foreach ($models as $model) {
            foreach ($this->exposedRelationsFromRequest($model) as $relationName) {
                $value = static::getModelsForRelation($model, $relationName);

                if (is_null($value)) {
                    continue;
                }

                foreach ($value as $obj) {

                    // Check whether the object is already included in the response on it's ID
                    $duplicate = false;
                    $items = $links->where($obj->getKeyName(), '=', $obj->getKey());
                    if (count($items) > 0) {
                        foreach ($items as $item) {
                            if ($item->getResourceType() === $obj->getResourceType()) {
                                $duplicate = true;
                                break;
                            }
                        }
                        if ($duplicate) {
                            continue;
                        }
                    }

                    //add type property
                    $attributes = $obj->getAttributes();
                    $attributes['type'] = $obj->getResourceType();
                    $obj->setRawAttributes($attributes);

                    $links->push($obj);
                }
            }
        }

        return $links->toArray();
    }
302887
public function setModels(array $models): ModelCollectionInterface
    {
        foreach ($this->models as $model) {
            $this->removeModel($model);
        }
        foreach ($models as $model) {
            $this->addModel($model);
        }

        return $this;
    }