Get the formatted value of an Eloquent model.

@param Model  $model
@param string $key
@param mixed  $value

@return mixed
543846
protected function getFormattedValue(Model $model, string $key, $value)
    {
        // Apply defined get mutator
        if ($model->hasGetMutator($key)) {
            return $model->mutateAttribute($key, $value);
        }

        // Cast to native PHP type
        if ($model->hasCast($key)) {
            return $model->castAttribute($key, $value);
        }

        // Honour DateTime attribute
        if ($value !== null && in_array($key, $model->getDates(), true)) {
            return $model->asDateTime($value);
        }

        return $value;
    }
852966
public function &__get( $key ) 
	{
		$value = null;

		// check if the modifier exists
		$has_modifier = method_exists( $this, '_get_modifier_'.$key );

		// try getting the item
		if ( array_key_exists( $key, $this->_data_store ) ) 
		{
			$value =& $this->_data_store[$key];

			if ( $has_modifier )
			{
				$tmpvalue = $this->{'_get_modifier_'.$key}( $value ); return $tmpvalue;
			}

			return $value;
		}

		if ( $has_modifier )
		{
			$value = $this->{'_get_modifier_'.$key}(); return $value;
		}

		// when a function extists we forward the call
		if ( method_exists( $this, $key ) )
		{
			$value = $this->__call_property( $key ); return $value;
		}

		throw new \InvalidArgumentException( "CCModel - Invalid or undefined model property '".$key."'." );
	}
749750
private function fetchValueForKey($key, $value)
    {
        if (in_array($key, $this->getDates())) {
            return trim($value) === '' ? null : $value;
        }

        if (! $this->hasSetMutator($key)) {
            $value = $this->getAttribute($key);
        }

        if ($this->isJsonCastable($key) && ! is_null($value)) {
            $value = is_string($value) ? $this->getJsonCastValue($value) : $value;
        }

        return $value;
    }
253787
public function typeString(Model $model, $key)
    {
        $config = $this->baseTypeString($model, $key);

        if ($this->isAutoGenerated($model, $key)) {
            $config .= '|readonly';
        }

        return $config;
    }
1091808
protected function getPropValue($model, PropDefinition $propDefinition)
    {
        // Get the model value via array access.
        $value = $model[$propDefinition->mapKey()] ?? null;

        // Format the value the property value.
        $value = $this->formatPropValue($value, $propDefinition);

        return $value;
    }
663232
protected function cache($key, $value)
    {
        if (array_has($this->model_cache, $key)) {
            return array_get($this->model_cache, $key);
        }

        if (is_callable($value)) {
            $result = $value();
        } else {
            $result = $value;
        }

        array_set($this->model_cache, $key, $result);

        return $result;
    }
373058
public function formatOutput($data, $model=null)
    {
        if ($data) {
            if (is_numeric(key($data))) {
                foreach ($data as $k => $v){
                    if (is_numeric($k) && is_array($v)) {
                        $data[$k] = static::formatOutputRecord($v, $model);
                    }
                }
            } else {
                $data = static::formatOutputRecord($data, $model);
            }
        }
        
        return $data;
    }
378612
protected function option(Model $model, $key, $default = null)
    {
        if (! method_exists($model, 'searchableOptions')) {
            return $default;
        }

        $options = $model->searchableOptions() ?: [];

        return array_get($options, $key, $default);
    }
528823
public function retrieve(Model $model, $source)
    {
        $this->model = $model;

        if ($this->isTranslated()) {

            $keys      = [];
            $localeKey = config('translatable.locale_key', 'locale');

            foreach ($model->translations as $translation) {
                /** @var Relation $relation */
                $relation = $translation->{$source}();

                $keys[ $translation->{$localeKey} ] = $this->getValueFromRelationQuery($relation);
            }

            return $keys;
        }

        $relation = $this->resolveModelSource($model, $source);

        if ( ! ($relation instanceof Relation)) {
            throw new UnexpectedValueException(
                "{$source} did not resolve to a relation for " . get_class($this) . " on " . get_class($model)
            );
        }

        try {
            return $this->getValueFromRelationQuery($relation);

        } catch (\Exception $e) {

            throw new RuntimeException(
                "Exception retrieving relation values for source '{$source}' "
                . "for form field key '{$this->formFieldData->key}'",
                0,
                $e
            );
        }
    }
1352133
public function getReferenceForModel(Model $model, $strategy = null, $source = null)
    {
        return $this->getReferenceValue($model, $strategy, $source);
    }
1130604
public function getFiledValue($model, $index)
    {
        $column = $this->translateColumnId($index);
        $value = $model->{$column->name};
        if ($column->format) {
            $value = call_user_func($column->format, $value);
        }
        return $value;
    }
987545
public function updateDataMeta( $model, $key, $value ) {

		$model->updateDataMeta( $key, $value );

		$model->refresh();

		return $model;
	}
969107
public function allBy($key, $value)
    {
        if (!request('preview')) {
            $this->published();
        }

        return $this->executeCallback(static::class, __FUNCTION__, func_get_args(), function () use ($key, $value) {
            return $this->prepareQuery($this->createModel())
                ->where($key, $value)
                ->order()
                ->get();
        });
    }
186233
public function clause($key, $method, $model = null)
    {
        $query = null;

        if (! is_null($model)) {
            $appModel = app($model);
            $query = DB::table(app($model)->table);

            if ($this->inBillingCycle) {
                $customer = Customer::retrieve($this->user->meta->stripe_id);
                $stripeSubscription = $customer->subscriptions->retrieve($this->subscription->stripe_id);

                $currentPeriodStart = Carbon::createFromTimestamp($stripeSubscription->current_period_start)->format('Y-m-d h:i:s');
                $currentPeriodEnd = Carbon::createFromTimestamp($stripeSubscription->current_period_end)->format('Y-m-d h:i:s');

                $query = $appModel->where('created_at', '>=', $currentPeriodStart)->where('created_at', '<=', $currentPeriodEnd);
            }
        }

        $clause = $this->config['plans'][$this->subscription->stripe_plan][$key];

        return $method($this->user, $this->subscription, $clause, $query);
    }
890446
public function display(string $fieldname, $value, string $model = null)
    {
        if (is_array($value)) {
            return implode(', ', $value);
        }

        $tableName = Inflector::camelize(Inflector::pluralize(str_replace('_id', '', $fieldname)));
        $table = TableRegistry::get($tableName);

        $tableConfig = [];

        $historizableBehavior = TableRegistry::get($model, $tableConfig)->behaviors()->get('Historizable');
        if (is_object($historizableBehavior) && method_exists($historizableBehavior, 'getRelationLink')) {
            return $historizableBehavior->getRelationLink($fieldname, $value);
        }

        return $value;
    }
375519
private function getValue($item, $model)
    {
        if (is_string($item)) {
            if ($model instanceof Model) {
                if (isset($model->{$item})) {
                    return $model->{$item};
                }
                return $item;
            } else {
                if (isset($model[$item])) {
                    return $model[$item];
                }
                return $item;
            }
        } else if (is_callable($item)) {
            return call_user_func($item, $model);
        }
        return '';
    }
445416
protected function getValueFromModel($model)
    {
        if ( ! ($model instanceof Model)) {
            return null;
        }

        return get_class($model)
             . static::CLASS_AND_KEY_SEPARATOR
             . $model->getKey();
    }