getAttribute() public method

Get an attribute from the model.
public getAttribute ( string $key ) : mixed
$key string
return mixed
 /**
  * @param Model $oModel
  * @return array
  */
 protected function resolveModelToArray(Model $oModel)
 {
     /** @var Key $oKey */
     $oKey = $oModel->getAttribute("key");
     /** @var Locale $oLocale */
     $oLocale = $oModel->getAttribute("locale");
     $aReturn = [$oModel->getKeyName() => $oModel->getKey(), "key" => $oKey ? $oKey->getAttribute(Key::COLUMN_NAME) : null, "locale" => $oLocale ? $oLocale->getAttribute(Locale::COLUMN_CODE) : null, Message::COLUMN_TEXT => $oModel->getAttribute(Message::COLUMN_TEXT)];
     return $aReturn;
 }
Ejemplo n.º 2
0
 /**
  * @param Model $result
  * @return string
  */
 protected function setDisplay($result)
 {
     if (is_array($this->config['display'])) {
         $displayString = '';
         foreach ($this->config['display'] as $key => $display) {
             if ($key !== 0) {
                 $displayString .= ' | ';
             }
             $displayString .= $result->getAttribute($display);
         }
         return $displayString;
     }
     return $result->getAttribute($this->config['display']);
 }
Ejemplo n.º 3
0
 /**
  * Get an attribute from the model.
  *
  * @param  string  $key
  * @return mixed
  */
 public function getAttribute($key)
 {
     if ($key == 'id') {
         $key = '@rid';
     }
     return parent::getAttribute($key);
 }
Ejemplo n.º 4
0
 /**
  * @param Model $model
  *
  * @return mixed
  */
 public function getModelTitle(Model $model)
 {
     if (is_string($this->title)) {
         return $model->getAttribute($this->title);
     }
     return call_user_func($this->title, $model);
 }
Ejemplo n.º 5
0
 public function getAttribute($key)
 {
     if ($this->hasAttribute($key)) {
         return parent::getAttribute($key);
     }
     return in_array($key, ['softDelete']) ? null : new FieldValue('{}');
 }
Ejemplo n.º 6
0
 /**
  * Get the value from the model.
  *
  * @param  string $name
  * @return mixed|null
  */
 protected function valueFromModel($name)
 {
     if (!$this->model) {
         return null;
     }
     return $this->model->getAttribute($name);
 }
Ejemplo n.º 7
0
 /**
  * Kiểm tra xem facebook user đã có trong sentinel-user chưa
  * Nếu có trả về user model
  * Chưa có trả về false
  *
  * @param \Illuminate\Database\Eloquent\Model $facebookUser
  *
  * @return bool | Model
  */
 public function isFacebookUserExisted(Model $facebookUser)
 {
     if (!!$facebookUser->getAttribute('user_id')) {
         return $facebookUser->user;
     } else {
         return false;
     }
 }
Ejemplo n.º 8
0
 /**
  * Associate the model instance to the given parent.
  *
  * @param  \Illuminate\Database\Eloquent\Model  $model
  * @return \Sgpatil\Orientdb\Eloquent\Edges\Relation
  */
 public function associate($model, $attributes = array())
 {
     $otherKey = $model instanceof Model ? $model->getAttribute($this->otherKey) : $model;
     $this->parent->setAttribute($this->foreignKey, $otherKey);
     if ($model instanceof Model) {
         $this->parent->setRelation($this->relation, $model);
     }
     return $this->parent;
 }
Ejemplo n.º 9
0
 /**
  * Add the slug when not explicitly stated.
  *
  * @param  Model  $model
  * @return void
  */
 public function saving(Model $model)
 {
     $hasManuallyAssignedSlug = $model->slug && $model->isDirty('slug');
     if (!$model->isDirty('name') || $hasManuallyAssignedSlug) {
         return;
     }
     $slug = str_slug($model->getAttribute($this->fieldToSlug));
     $model->setAttribute($this->slugAttribute, $slug);
 }
Ejemplo n.º 10
0
 /**
  * @return mixed
  */
 protected function getModelValue()
 {
     $value = $this->model->getAttribute($this->getModelKey());
     if ($value instanceof Model) {
         $value = $value->getAttribute($value->getKeyName());
     } elseif ($value instanceof Collection) {
         $value = $value->pluck('id')->all();
     }
     return $value;
 }
Ejemplo n.º 11
0
 /**
  * Get an attribute from the model with custom accessor.
  *
  * @param  string $key
  * @return mixed
  */
 public function getAttribute($key)
 {
     if (isset($this->mutations[$key])) {
         return $this->mutations[$key];
     }
     if (array_key_exists($key, $mutatables = static::getMutatables())) {
         return $this->mutateExtensionAttribute($key, $mutatables[$key]);
     }
     return parent::getAttribute($key);
 }
Ejemplo n.º 12
0
 /**
  * Observe model saving for User.
  *
  * @param  \Illuminate\Database\Eloquent\Model  $model
  *
  * @return void
  */
 public function updating(Model $model)
 {
     $changes = [];
     $watchlist = (array) Arr::get($this->config, 'watchlist', []);
     foreach ($watchlist as $attribute) {
         if ($model->isDirty($attribute)) {
             $changes[$attribute] = $model->getAttribute($attribute);
         }
     }
     $recipient = new GenericRecipient($model->getOriginal('email'), $model->getRecipientName());
     $this->factory->notify($recipient, $model, $changes, $this->config);
 }
Ejemplo n.º 13
0
 /**
  * Save a new model and attach it to the parent model.
  *
  * @param  \Illuminate\Database\Eloquent\Model  $model
  * @return \Illuminate\Database\Eloquent\Model
  */
 protected function performInsert(Model $model)
 {
     // Create a new key if needed.
     if (!$model->getAttribute('_id')) {
         $model->setAttribute('_id', new MongoId());
     }
     $result = $this->query->update(array($this->localKey => $model->getAttributes()));
     if ($result) {
         $this->associate($model);
     }
     return $result ? $model : false;
 }
Ejemplo n.º 14
0
/**
 * Format a Carbon date if available to a simplified format
 * for form input element. Uses old data if available.
 *
 * @param  \Illuminate\Database\Eloquent\Model  $model
 * @param  string  $field
 * @param  string  $default
 * @return string
 */
function format_date_form_field($model, $field, $default = 'MM/DD/YYYY')
{
    $oldDate = old($field);
    if ($oldDate) {
        return $oldDate;
    }
    $attribute = $model->getAttribute($field);
    if ($attribute && $attribute instanceof Carbon) {
        return $attribute->format('Y-m-d');
    }
    return $default;
}
Ejemplo n.º 15
0
 /**
  * Get an attribute from the model.
  *
  * @param  string $key
  * @throws \Exception
  * @return mixed
  */
 public function getAttribute($key)
 {
     // If the attribute is not already available to the
     // model, let's look for any configured relationships
     // that match the $key and return a Collection|static
     if (!($attribute = parent::getAttribute($key))) {
         if ($relationship = $this->resolveRelationship($key)) {
             $attribute = $relationship->getResults();
             $this->relations[$key] = $relationship;
         }
     }
     return $attribute;
 }
Ejemplo n.º 16
0
 /**
  * Get the default value for this relation.
  *
  * @param  \Illuminate\Database\Eloquent\Model  $model
  * @return \Illuminate\Database\Eloquent\Model|null
  */
 protected function getDefaultFor(Model $model)
 {
     if (!$this->withDefault) {
         return;
     }
     $instance = $this->related->newInstance()->setAttribute($this->getPlainForeignKey(), $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;
 }
Ejemplo n.º 17
0
 /**
  * Get an attribute from the model. If nothing is found, attempt to load
  * a custom relation method with this key.
  *
  * @param string $key
  * @return mixed
  */
 public function getAttribute($key)
 {
     if (!is_null($value = parent::getAttribute($key))) {
         return $value;
     }
     // If a custom relation with this key has been set up, then we will load
     // and return results from the query and hydrate the relationship's
     // value on the "relationships" array.
     if (!$this->relationLoaded($key) && ($relation = $this->getCustomRelation($key))) {
         if (!$relation instanceof Relation) {
             throw new LogicException('Relationship method must return an object of type ' . 'Illuminate\\Database\\Eloquent\\Relations\\Relation');
         }
         return $this->relations[$key] = $relation->getResults();
     }
 }
Ejemplo n.º 18
0
 /**
  * The default error bag.
  *
  * @var string
  */
 private function getValidationData($table, $keys, Model $model = NULL)
 {
     $config = app('config')->get('validation.' . $table);
     $keys == '*' && ($keys = array_keys($config));
     $validation_data = array_keyfilter($config, $keys);
     $rules = $messages = $attributes = [];
     foreach ($validation_data as $k => $v) {
         empty($v['rules']) && ($v['rules'] = []);
         !is_array($v['rules']) && ($v['rules'] = explode('|', $v['rules']));
         foreach ($v['rules'] as &$vv) {
             $vv = str_replace(',{{attribute}}', ',' . $k, $vv);
             $vv = preg_replace_callback('/,\\{\\{([a-z0-9_\\-]*)\\}\\}/i', function ($matches) use($model) {
                 return !empty($model) ? $model->offsetExists($matches[1]) ? ',' . $model->getAttribute($matches[1]) : '' : '';
             }, $vv);
         }
         isset($v['rules']) && ($rules[$k] = $v['rules']);
         isset($v['message']) && ($messages[$k] = $v['message']);
         isset($v['name']) && ($attributes[$k] = $v['name']);
     }
     return compact('rules', 'messages', 'attributes');
 }
Ejemplo n.º 19
0
 /**
  * Associate the model instance to the given parent.
  *
  * @param  \Illuminate\Database\Eloquent\Model  $model
  * @return \Illuminate\Database\Eloquent\Model
  */
 public function associate(Model $model)
 {
     $this->parent->setAttribute($this->foreignKey, $model->getAttribute($this->otherKey));
     return $this->parent->setRelation($this->relation, $model);
 }
Ejemplo n.º 20
0
 /**
  * Retrieves an inventory stock from a given location.
  *
  * @param Model $location
  *
  * @throws StockNotFoundException
  *
  * @return mixed
  */
 public function getStockFromLocation(Model $location)
 {
     $stock = $this->stocks()->where('location_id', $location->getKey())->first();
     if ($stock) {
         return $stock;
     } else {
         $message = Lang::get('inventory::exceptions.StockNotFoundException', ['location' => $location->getAttribute('name')]);
         throw new StockNotFoundException($message);
     }
 }
 /**
  * Goes through all related columns and sets the proper values for this row
  *
  * @param \Illuminate\Database\Eloquent\Model	$item
  * @param array									$outputRow
  *
  * @return void
  */
 public function parseOnTableColumns($item, array &$outputRow)
 {
     $columns = $this->columnFactory->getColumns();
     $includedColumns = $this->columnFactory->getIncludedColumns($this->fieldFactory->getEditFields());
     $relatedColumns = $this->columnFactory->getRelatedColumns();
     //loop over both the included and related columns
     foreach (array_merge($includedColumns, $relatedColumns) as $field => $col) {
         $attributeValue = $item->getAttribute($field);
         //if this column is in our objects array, render the output with the given value
         if (isset($columns[$field])) {
             $outputRow[$field] = array('raw' => $attributeValue, 'rendered' => $columns[$field]->renderOutput($attributeValue));
         } else {
             $outputRow[$field] = array('raw' => $attributeValue, 'rendered' => $attributeValue);
         }
     }
 }
Ejemplo n.º 22
0
 /**
  * Validate current user.
  *
  * @param  \Orchestra\Model\User|\Illuminate\Database\Eloquent\Model  $user
  * @param  array  $input
  *
  * @return bool
  */
 protected function validateCurrentUser($user, array $input)
 {
     return (string) $user->getAttribute('id') === $input['id'];
 }
Ejemplo n.º 23
0
 public function apply(Builder $builder, Model $model)
 {
     $level_key = $model->getAttribute('level_key') ?: 'level';
     $builder->where($level_key, '>', 1);
 }
Ejemplo n.º 24
0
 /**
  * Get an attribute from the model.
  *
  * @param  string  $key
  * @return mixed
  */
 public function getAttribute($key)
 {
     // Check if the key is an array dot notation.
     if (str_contains($key, '.') and array_has($this->attributes, $key)) {
         return $this->getAttributeValue($key);
     }
     $camelKey = camel_case($key);
     // If the "attribute" exists as a method on the model, it may be an
     // embedded model. If so, we need to return the result before it
     // is handled by the parent method.
     if (method_exists($this, $camelKey)) {
         $method = new ReflectionMethod(get_called_class(), $camelKey);
         // Ensure the method is not static to avoid conflicting with Eloquent methods.
         if (!$method->isStatic()) {
             $relations = $this->{$camelKey}();
             // This attribute matches an embedsOne or embedsMany relation so we need
             // to return the relation results instead of the interal attributes.
             if ($relations instanceof EmbedsOneOrMany) {
                 // If the key already exists in the relationships array, it just means the
                 // relationship has already been loaded, so we'll just return it out of
                 // here because there is no need to query within the relations twice.
                 if (array_key_exists($key, $this->relations)) {
                     return $this->relations[$key];
                 }
                 // Get the relation results.
                 return $this->getRelationshipFromMethod($key, $camelKey);
             }
         }
     }
     return parent::getAttribute($key);
 }
Ejemplo n.º 25
0
 /**
  * Set identifier from user object.
  *
  * @param  \Illuminate\Database\Eloquent\Model|object  $user
  * @param  string  $attribute
  *
  * @return $this
  */
 public function setIdentifierFromUser($user, $attribute = 'email')
 {
     return $this->setIdentifier($user->getAttribute($attribute));
 }
Ejemplo n.º 26
0
 /**
  * Get an attribute from the model.
  * Overrided from {@link Eloquent} to implement recognition of the {@link $relationsData} array.
  *
  * @param  string $key
  * @return mixed
  */
 public function getAttribute($key)
 {
     $attr = parent::getAttribute($key);
     if ($attr === null) {
         $camelKey = camel_case($key);
         if (array_key_exists($camelKey, static::$relationsData)) {
             $this->relations[$key] = $this->{$camelKey}()->getResults();
             return $this->relations[$key];
         }
     }
     return $attr;
 }
Ejemplo n.º 27
0
 /**
  * Associate a new model instance to the given parent, without saving it to the database.
  *
  * @param  \Illuminate\Database\Eloquent\Model  $model
  * @return \Illuminate\Database\Eloquent\Model
  */
 protected function associateNew($model)
 {
     // Create a new key if needed.
     if (!$model->getAttribute('_id')) {
         $model->setAttribute('_id', new MongoId());
     }
     $records = $this->getEmbedded();
     // Add the new model to the embedded documents.
     $records[] = $model->getAttributes();
     return $this->setEmbedded($records);
 }
Ejemplo n.º 28
0
 /**
  * Get an attribute from the model.
  * Overrided from {@link Eloquent} to implement recognition of the relation.
  * @return mixed
  */
 public function getAttribute($key)
 {
     // Before Event
     if (($attr = $this->fireEvent('model.beforeGetAttribute', [$key], true)) !== null) {
         return $attr;
     }
     $attr = parent::getAttribute($key);
     if ($attr === null && $this->hasRelation($key) && !array_key_exists($key, $this->relations)) {
         $attr = $this->relations[$key] = $this->{$key}()->getResults();
     }
     // After Event
     if (($_attr = $this->fireEvent('model.getAttribute', [$key, $attr], true)) !== null) {
         return $_attr;
     }
     return $attr;
 }
Ejemplo n.º 29
0
 public function getAttribute($key)
 {
     return parent::getAttribute(snake_case($key));
 }
Ejemplo n.º 30
0
 /**
  * Gets an attribute value without running through the manipulators.
  *
  * @param $key
  *
  * @return mixed
  */
 public function getOriginalAttribute($key)
 {
     return parent::getAttribute($key);
 }