本文整理汇总了PHP中Illuminate\Database\Eloquent\Model::getAttribute方法的典型用法代码示例。如果您正苦于以下问题:PHP Model::getAttribute方法的具体用法?PHP Model::getAttribute怎么用?PHP Model::getAttribute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Database\Eloquent\Model
的用法示例。
在下文中一共展示了Model::getAttribute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: resolveModelToArray
/**
* @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;
}
示例2: setDisplay
/**
* @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']);
}
示例3: getAttribute
/**
* Get an attribute from the model.
*
* @param string $key
* @return mixed
*/
public function getAttribute($key)
{
if ($key == 'id') {
$key = '@rid';
}
return parent::getAttribute($key);
}
示例4: updating
/**
* 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);
}
示例5: getModelTitle
/**
* @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);
}
示例6: getAttribute
public function getAttribute($key)
{
if ($this->hasAttribute($key)) {
return parent::getAttribute($key);
}
return in_array($key, ['softDelete']) ? null : new FieldValue('{}');
}
示例7: valueFromModel
/**
* 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);
}
示例8: isFacebookUserExisted
/**
* 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;
}
}
示例9: associate
/**
* 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;
}
示例10: saving
/**
* 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);
}
示例11: getModelValue
/**
* @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;
}
示例12: getAttribute
/**
* 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);
}
示例13: performInsert
/**
* 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;
}
示例14: format_date_form_field
/**
* 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;
}
示例15: getAttribute
/**
* 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;
}