get simple array from Model.

@param Model $model

@return $result
359676
public function getModelArray(Model $model)
    {
        $result = [];
        foreach ($model->getAttributes() as $key => $value) {
            $result[] = ['type' => 'text', 'name' => $key, 'key' => $key.' :', 'value' => $value];
        }
        unset($result[0]);

        return $result;
    }
1251456
public static function checkModel($errors, Model $model) : array
    {
        $output = [];
        if (!is_array($errors)) {
            return $output;
        }
        foreach ($errors as $attribute => $message) {
            $obj = $model;
            if (strpos($attribute, '.') !== false) {
                list($nested, $attr) = explode('.', $attribute);
                if (isset($obj->{$nested}) && $obj->{$nested} instanceof Model) {
                    $obj       = $obj->{$nested};
                    $attribute = $attr;
                }
            }
            if ($obj->hasProperty($attribute)) {
                $output[Html::getInputId($obj, $attribute)] = $message;
            } else {
                $output[] = $message;
            }
        }
        return $output;
    }
919139
protected function getRelatedModels(Model $model)
    {
        // Store the class name
        $modelClass = get_class($model);

        // Check if we already know the related models for this model
        if (!isset($this->relatedModels[$modelClass]))
        {
            $relatedModels = [];

            $methods = with(new \ReflectionClass($model))->getMethods();

            // Iterate all class methods
            foreach ($methods as $method)
            {
                // Check if this method returns an Eloquent relation
                if ($method->class == $modelClass &&
                    preg_match('/@return\s+\\\\Illuminate\\\\Database\\\\Eloquent\\\\Relations/', $method->getDocComment())
                )
                {
                    // Get the method name, so that we can call it on the model
                    $relationMethod = $method->name;

                    // Find the relation
                    $relation = $model->$relationMethod();

                    if ($relation instanceof Relation)
                    {
                        // Find the related model
                        $related = $relation->getRelated();

                        // Store the method to help build the inverse path
                        $this->relationClassMethods[$modelClass][get_class($related)] = $relationMethod;

                        $relatedModels[] = ['model' => $related, 'method' => $method];
                    }
                }
            }

            // Cache related models for this model
            $this->relatedModels[$modelClass] = $relatedModels;

            // Return the related models
            return $relatedModels;
        } else
        {
            // Return from cache
            return $this->relatedModels[$modelClass];
        }
    }
48841
private function queryAttributes(Model $model)
    {
        $data = [
            'user_id'    => user()->id,
            'namespace'  => get_class($model),
            'foreign_id' => $model->id
        ];
        (is_null($this->field)) ? array_set($data, 'field_class', get_called_class()) : array_set($data, 'field_id', $this->field->id);
        return $data;
    }
694699
public function getTransformedFiles(Model $model) {
        if (isset($this->_uploads[$model->alias])) {
            return $this->_uploads[$model->alias]->getTransformedFiles();
        }

        return array();
    }
559423
public function get(ActiveRecord $model)
    {
        $key = $model::className() . '-' . $model->getPrimaryKey();
        return ArrayHelper::getValue($this->_storage, $key);
    }
902043
protected function collectColumns(Model $model = null)
    {
        if (!$model) {
            return new MutableCollection([]);
        }

        $pk = $model->getKeyName();

        $fillable = array_merge(
            is_array($pk) ? $pk : [$pk],
            $model->getFillable()
        );
        $hidden = $model->getHidden();

        if ($model instanceof Translatable && method_exists($model, 'getTranslatedAttributes')) {
            $fillable = array_merge($fillable, $model->getTranslatedAttributes());
            $hidden = array_merge($hidden, $model->getTranslationModel()->getHidden());
        }

        $fillable = array_unique(array_diff($fillable, $hidden));

        /**
         * Create collection.
         */
        $elements = new MutableCollection($fillable);

        if ($this->includeDateColumns && count($dates = $model->getDates())) {
            // allow setting specific timestamp: created_at
            if (is_string($this->includeDateColumns)) {
                $dates = array_intersect($dates, [$this->includeDateColumns]);

                $elements = $elements->merge($dates);
            } else {
                // add timestamps group
                $elements->group('dates', function (Group $group) use ($dates) {
                    $group->merge($dates);

                    return $group;
                });
            }
        }

        return $elements->build(
            new GridDecorator($model)
        );
    }
1335297
public static function extractModelAndKeys($model, array $keys = null)
    {
        if (! is_null($keys)) {
            if (is_string($model)) {
                $model = new $model;
            }

            return [$model, $keys];
        }

        if ($model instanceof Model) {
            return [$model, [$model->getKey()]];
        }

        if ($model instanceof Collection) {
            $keys = $model->map(function ($model) {
                return $model->getKey();
            });

            return [$model->first(), $keys];
        }
    }
120578
public static function import(Model $model)
    {
        Utils\Utils::arrayPathSet(self::$models, self::getPath($model), $model);
    }
1097777
public function toArray(Model $model)
    {
        // start with the base representation of the model
        if (method_exists($model, 'withoutArrayHook')) {
            $model->withoutArrayHook();
        }
        $result = $model->toArray();

        // apply namespacing to excluded properties
        $namedExc = [];
        foreach ($this->exclude as $k) {
            array_set($namedExc, $k, true);
        }

        // apply namespacing to included properties
        $namedInc = [];
        foreach ($this->include as $k) {
            array_set($namedInc, $k, true);
        }

        // apply namespacing to expanded properties
        $namedExp = [];
        foreach ($this->expand as $k) {
            array_set($namedExp, $k, true);
        }

        // remove excluded properties
        foreach (array_keys($result) as $k) {
            if (isset($namedExc[$k]) && !is_array($namedExc[$k])) {
                unset($result[$k]);
            }
        }

        // add included properties
        foreach (array_keys($namedInc) as $k) {
            if (!isset($result[$k]) && isset($namedInc[$k])) {
                $result[$k] = $model->$k;
                if ($result[$k] instanceof Model) {
                    $subExc = array_value($namedExc, $k);
                    $subInc = array_value($namedInc, $k);
                    $subExp = array_value($namedExp, $k);

                    // convert exclude, include, and expand into dot notation
                    // then take the keys for a flattened dot notation
                    $flatExc = is_array($subExc) ? array_keys(array_dot($subExc)) : [];
                    $flatInc = is_array($subInc) ? array_keys(array_dot($subInc)) : [];
                    $flatExp = is_array($subExp) ? array_keys(array_dot($subExp)) : [];

                    $serializer = new self($this->request);
                    $serializer->setExclude($flatExc)
                        ->setInclude($flatInc)
                        ->setExpand($flatExp);

                    $result[$k] = $serializer->toArray($result[$k]);
                }
            }
        }

        // expand any relational model properties
        $result = $this->expand($model, $result, $namedExc, $namedInc, $namedExp);

        // apply hooks, if available
        if (method_exists($model, 'toArrayHook')) {
            $model->toArrayHook($result, $namedExc, $namedInc, $namedExp);
        }

        // order the properties array by name for consistency
        // since it is constructed in a random order
        ksort($result);

        return $result;
    }
1111196
protected function getModelPrimaryKeyString($model)
    {
        return is_array($model->getPrimaryKey()) ? implode('-', $model->getPrimaryKey()) : $model->getPrimaryKey();
    }
1233746
protected function getRelations($model)
    {
        $methods = get_class_methods($model);
        if (!$methods) {
            return [];
        }
        foreach ($methods as $method) {
            if (Str::startsWith($method, 'get') && Str::endsWith($method, 'Attribute') && $method !== 'getAttribute') {
                $name = Str::snake(substr($method, 3, -9));
                if (!empty($name)) {
                    $this->setProperty($name, null, true, null);
                }
            } elseif (Str::startsWith($method, 'set') && Str::endsWith($method, 'Attribute') && $method !== 'setAttribute') {
                $name = Str::snake(substr($method, 3, -9));
                if (!empty($name)) {
                    $this->setProperty($name, null, null, true);
                }
            } elseif (Str::startsWith($method, 'scope') && $method !== 'scopeQuery') {
                $name = Str::camel(substr($method, 5));
                if (!empty($name)) {
                    $reflection = new \ReflectionMethod($model, $method);
                    $args       = $this->getParameters($reflection);
                    array_shift($args);
                    $this->setMethod($name, '\Illuminate\Database\Query\Builder|\\' . $reflection->class, $args);
                }
            } elseif (!method_exists('Illuminate\Database\Eloquent\Model', $method) && !Str::startsWith($method, 'get')) {
                $reflection = new ReflectionMethod($model, $method);
                $file       = new SplFileObject($reflection->getFileName());
                $file->seek($reflection->getStartLine() - 1);
                $code       = '';
                while ($file->key() < $reflection->getEndLine()) {
                    $code .= $file->current();
                    $file->next();
                }
                $code  = trim(preg_replace('/\s\s+/', '', $code));
                $begin = strpos($code, 'function(');
                $code  = substr($code, $begin, strrpos($code, '}') - $begin + 1);

                foreach (array('hasOne', 'belongsTo') as $relation) {
                    $search = '$this->' . $relation . '(';
                    if ($pos    = stripos($code, $search)) {
                        $relationObj = $model->$method();
                        if ($relationObj instanceof Relation) {
                            $relatedModel = '\\' . get_class($relationObj->getRelated());

                            $relations = ['hasManyThrough', 'belongsToMany', 'hasMany', 'morphMany', 'morphToMany'];
                            if (in_array($relation, $relations)) {
                                $this->setProperty($method, $this->getCollectionClass($relatedModel) . '|' . $relatedModel . '[]', true, null);
                            } elseif ($relation === "morphTo") {
                                $this->setProperty($method, '\Illuminate\Database\Eloquent\Model|\Eloquent', true, null);
                            } else {
                                $this->setProperty($method, $relatedModel, true, null);
                            }
                        }
                    }
                }
            }
        }
        return $this->properties;
    }
1323938
protected function serializeModel($model)
    {
        if ($this->request->getIsHead()) {
            return null;
        }

        [$fields, $expand] = $this->getRequestedFields();
        return $model->toArray($fields, $expand);
    }
1270484
protected function getModelByKey(Model $model, $key)
    {
        return $model::withoutGlobalScopes()
            ->where($model->getKeyName(), $key)
            ->first();
    }
535304
protected function getTableAndDatabase($model)
    {
        $table = $model->getConnection()->getTablePrefix() . $model->getTable();

        $database = null;

        if (strpos($table, '.')) {
            list($database, $table) = explode('.', $table);
        }

        return [$table, $database];
    }
513057
public function sources($model = null) {
		$params = compact('model');

		return Filters::run($this, __FUNCTION__, $params, function($params) {
			$schema = $this->connection->quote($this->_config['schema']);

			$sql  = "SELECT table_name as name FROM INFORMATION_SCHEMA.tables";
			$sql .= " WHERE table_schema = {$schema}";

			if (!$result = $this->_execute($sql)) {
				return null;
			}
			$sources = [];

			foreach ($result as $row) {
				$sources[] = $row[0];
			}
			return $sources;
		});
	}
31683
protected function getDefaultFor(Model $model)
    {
        if (! $this->withDefault) {
            return;
        }

        $instance = $this->related->newInstance()->setAttribute(
            $this->getForeignKeyName(),
            $model->getAttribute($this->localKey)
        );

        if (is_callable($this->withDefault)) {
            return call_user_func($this->withDefault, $instance) ?: $instance;
        }

        if (is_array($this->withDefault)) {
            $instance->forceFill($this->withDefault);
        }

        return $instance;
    }