Get the model factory attributes of the model being built.

@param  Model $model
@return array
425401
protected function getFactoryAttributes(Model $model)
    {
        // This package allows developers to specify attributes for single locales
        // in their factory definitions with the attribute:locale syntax,
        // but the Eloquent\FactoryBuilder's raw() method interprets them as regular attributes,
        // and if we were to make() the model and then call getAttribute() everytime,
        // such attributes would cause Translatable to run a query for each model instance.
        // We'll resort to binding a closure to the factory to get the defined states,
        // and pass them as custom attributes to raw().
        // This has the added bonus over make()->getAttributes() of delaying the calling
        // of any closure in factory definitions/states, allowing them to receive the model
        // with more attributes set and the inserted primary keys as arguments,
        // like the closure custom attributes passed to Populator.
        $factory = app(Eloquent\Factory::class);

        $states = $this->isTranslation($model) ? $this->translationStates : $this->states;

        $modelClass = get_class($model);

        $modelIsDefined = call_user_func(\Closure::bind(function () use ($modelClass) {
            return isset($this->definitions[$modelClass]);
        }, $factory, $factory));

        if (!$modelIsDefined) {
            // If the model is not defined in the factory and the developer didn't apply any state,
            // that means he doesn't need the factory for this model, so we'll return an empty array.
            if (!$states) {
                return [];
            }

            // If the model doesn't have a factory definition,
            // but the developer still wants to apply states,
            // we'll create a dummy definition of the model to allow it.
            $factory->define($modelClass, function () {
                return [];
            });
        }

        return $factory->raw($modelClass, $this->getStateAttributes($factory, $states, $modelClass));
    }
1317033
public function getBehaviorCallbacks(Model $model) {
        $callbacks = array();
        $behaviors = Configure::read('Admin.behaviorCallbacks');

        foreach ($behaviors as $behavior => $methods) {
            if (!$model->Behaviors->loaded($behavior)) {
                continue;
            }

            foreach ($methods as $method => $options) {
                if (is_string($options)) {
                    $options = array('title' => $options, 'access' => 'update');
                } else {
                    $options = $options += array('access' => 'update');
                }

                if ($this->hasAccess($model->qualifiedName, $options['access'])) {
                    $callbacks[$method] = array(
                        'title' => __d('admin', $options['title'], $model->singularName),
                        'behavior' => Inflector::underscore($behavior),
                        'method' => $method
                    );
                }
            }
        }

        return $callbacks;
    }
104031
public function getCount(Model $model) {
        return $model->find('count', array(
            'cache' => $model->alias . '::getCount',
            'cacheExpires' => $this->getExpiration($model)
        ));
    }
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;
    }
1090328
protected function getAttributes($model)
    {
        $attributes = $model->attributesToArray();
        foreach( $this->immutableAttributes as $attribute ) {
            unset( $attributes[ $attribute] );
        }

        return $attributes;
    }
350131
public function referencing(Model $model)
    {
        $references = [];

        // TODO: SchemaManager should do this
        foreach ($this->schemas as $schema) {
            $references = array_merge($references, $schema->referencing($model->getBlueprint()));
        }

        // TODO: ModelManager should do this
        foreach ($references as &$related) {
            $blueprint = $related['blueprint'];
            $related['model'] = $model->getBlueprint()->is($blueprint->schema(), $blueprint->table())
                ? $model
                : $this->makeModel($blueprint->schema(), $blueprint->table(), false);
        }

        return $references;
    }
477892
public function retrieve(Model $model, $source)
    {
        if ($this->isTranslated()) {
            return $model->translations->mapWithKeys(function (Model $model) {
                /** @var Taggable $model */
                return [ $model->{config('translatable.locale_key', 'locale')} => $model->tagNames() ];
            });
        }

        return $model->tagNames();
    }
640580
public static function loadRelationsAttributesRecursive(Model $model)
    {
        $attributes = $model->getAttributes();

        foreach ($attributes as $key => $value) {
            if (method_exists($model, $key)) {
                $reflection_method = new ReflectionMethod($model, $key);

                // Check if method class has or inherits Illuminate\Database\Eloquent\Model
                if(!static::isClassInClass("Illuminate\Database\Eloquent\Model", $reflection_method->class)) {
                    $relation = $model->$key();

                    if ($relation instanceof Relation) {
                        // Check if the relation field is single model or collections
                        if (is_null($value) === true || !static::isMultiLevelArray($value)) {
                            $value = [$value];
                        }

                        $models = static::hydrateRecursive($relation->getModel(), $value, $relation);

                        // Unset attribute before match relation
                        unset($model[$key]);
                        $relation->match([$model], $models, $key);
                    }
                }
            }
        }
    }
203622
protected function showDatabaseFields(Model $model)
    {
        $this->title("Table {$model->getTable()} :");

        if ( ! $this->db->isConnected()) {
            $this->warn("Not Connected to databse, please check your connection config\r");
        } else {
            $fields = $this->db->getFields($model->getTable());
            $headers = ['name', 'type', 'null', 'length', 'unsigned', 'autoincrement', 'primary_key', 'foreign_key'];

            $this->table($headers, $fields->toArray());
        }
    }
1169806
protected function setForeignAttributesForCreate(Model $model)
    {
        $property = $this->getPlainForeignKey();

        $model->{$property} = $this->getParentKey();

        //
        $property = $this->getPlainMorphType();

        $model->{$property} = $this->morphClass;
    }
1049648
public function getModelLinks(Model $model) {
        $models = Configure::read('Admin.modelLinks');

        if (isset($models[$model->qualifiedName])) {
            return $models[$model->qualifiedName];
        }

        return array();
    }
286307
protected function getResponse($model)
    {
        $hiddenAttributes = array_filter(explode(',', Yii::$app->getRequest()->getQueryParam('hide', '')));
        $fields = FormBuilder::getFormFields($model, $this->getFields($model, 'form'), false, $hiddenAttributes);

        return [
            'model' => $model,
            'fields' => empty($fields) ? [] : [$fields],
            'relations' => $this->getModelRelations($model, $this->getExtraFields($model)),
        ];
    }
625509
private function getNodeValues($model)
    {
        $attribute = "{$this->name}_uc_first";
        return [
            'id'        => $model->id,
            'parent'    => $model->parent_id,
            'name'      => $model->$attribute,
            'level'     => $model->depth,
            'type'      => $model->isLeaf() ? 'file' : 'folder'
        ];
    }
347539
protected static function encryptAttributes(Model $model)
    {
        foreach (static::getEncryptedAttributes() as $attribute) {
            try {
                $model->$attribute = static::getEncrypter()->encrypt($model->$attribute);
            } catch (EncryptException $e) {
            }
        }

        return $model;
    }
137064
private function getCriteria($model): array
    {
        $criteria = [];
        foreach ($this->uniqueProperties as $uniqueProperty) {
            $criteria[$uniqueProperty] = (new PropertyAccessor($uniqueProperty))->getValue($model);
        }

        return $criteria;
    }
449194
public function scaffoldViewColumns(Model $model)
    {
        $items = new Mutable();

        $attributes = \admin\helpers\eloquent_attributes($model);

        foreach ($attributes as $key => $value) {
            $items->push($key);
        }

        return $items->build(
            new GridDecorator($model)
        );
    }
917982
protected function getDefaultFor(Model $model)
    {
        if (! $this->withDefault) {
            return;
        }

        $instance = $this->related->newInstance();

        $foreignKey = $this->getForeignKeyName();

        if (is_array($foreignKey)) { //Check for multi-columns relationship
            foreach ($foreignKey as $index => $key) {
                $instance->setAttribute($key, $model->getAttribute($this->localKey[$index]));
            }
        } else {
            $instance->setAttribute($foreignKey, $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;
    }