当前位置: 首页>>代码示例>>PHP>>正文


PHP Model::setAttribute方法代码示例

本文整理汇总了PHP中Illuminate\Database\Eloquent\Model::setAttribute方法的典型用法代码示例。如果您正苦于以下问题:PHP Model::setAttribute方法的具体用法?PHP Model::setAttribute怎么用?PHP Model::setAttribute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Illuminate\Database\Eloquent\Model的用法示例。


在下文中一共展示了Model::setAttribute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: remove

 /**
  * Removes a model from this relationship type.
  */
 public function remove(Model $model, $sessionKey = null)
 {
     if ($sessionKey === null) {
         $options = $this->parent->getRelationDefinition($this->relationName);
         if (array_get($options, 'delete', false)) {
             $model->delete();
         } else {
             /*
              * Make this model an orphan ;~(
              */
             $model->setAttribute($this->getPlainForeignKey(), null);
             $model->setAttribute($this->getPlainMorphType(), null);
             $model->save();
         }
         /*
          * Use the opportunity to set the relation in memory
          */
         if ($this instanceof MorphOne) {
             $this->parent->setRelation($this->relationName, null);
         } else {
             $this->parent->reloadRelations($this->relationName);
         }
     } else {
         $this->parent->unbindDeferred($this->relationName, $model, $sessionKey);
     }
 }
开发者ID:jBOKA,项目名称:library,代码行数:29,代码来源:MorphOneOrMany.php

示例2: saving

 /**
  * Save user profile.
  *
  * @param  \Orchestra\Model\User|\Illuminate\Database\Eloquent\Model  $user
  * @param  array  $input
  *
  * @return void
  */
 protected function saving($user, array $input)
 {
     $user->setAttribute('email', $input['email']);
     $user->setAttribute('fullname', $input['fullname']);
     $this->fireEvent('updating', [$user]);
     $this->fireEvent('saving', [$user]);
     $user->saveOrFail();
     $this->fireEvent('updated', [$user]);
     $this->fireEvent('saved', [$user]);
 }
开发者ID:quetzyg,项目名称:foundation,代码行数:18,代码来源:ProfileUpdater.php

示例3: remove

 /**
  * Removes a model from this relationship type.
  */
 public function remove(Model $model, $sessionKey = null)
 {
     if ($sessionKey === null) {
         // Make this model an orphan ;~(
         $model->setAttribute($this->getPlainForeignKey(), null);
         $model->setAttribute($this->getPlainMorphType(), null);
         $model->save();
     } else {
         $this->parent->unbindDeferred($this->relationName, $model, $sessionKey);
     }
 }
开发者ID:tamboer,项目名称:LaravelOctober,代码行数:14,代码来源:MorphOneOrMany.php

示例4: setAttribute

 /**
  * Set a given attribute on the model.
  * Check if filtered first.
  *
  * @param  string  $key
  * @param  mixed   $value
  * @return void
  */
 public function setAttribute($key, $value)
 {
     if (in_array($key, $this->filtered)) {
         $value = \Filter::filter($value, $this->filterReplace);
     }
     parent::setAttribute($key, $value);
 }
开发者ID:rtablada,项目名称:profane,代码行数:15,代码来源:model.php

示例5: setAttribute

 /**
  * Set model attribute. Extend laravel attribute casting mutators by serialized array
  * @param string $key
  * @param mixed $value
  * @return LaravelModel
  */
 public function setAttribute($key, $value)
 {
     if ($value !== null && $this->isSerializeCastable($key)) {
         $value = $this->asSerialize($value);
     }
     return parent::setAttribute($key, $value);
 }
开发者ID:phpffcms,项目名称:ffcms-core,代码行数:13,代码来源:ActiveModel.php

示例6: mergeValues

 /**
  * Merges EAV "values" into the entity model, for easy access and
  * manipulation.
  *
  * @param  \Illuminate\Database\Eloquent\Model  $model
  * @param  \Illuminate\Database\Eloquent\Collection  $collection
  * @return void
  */
 protected function mergeValues(Model $model, Collection $values)
 {
     foreach ($values as $value) {
         $attribute = $value->getRelation($value->getAttributeRelation());
         $model->setAttribute($attribute->getAttributeKey(), $value->getValueKey());
     }
 }
开发者ID:sohailaammarocs,项目名称:lfc,代码行数:15,代码来源:EavValues.php

示例7: setAttribute

 /**
  * Overrides the method to ignore the remember token.
  */
 public function setAttribute($key, $value)
 {
     $isRememberTokenAttribute = $key == $this->getRememberTokenName();
     if (!$isRememberTokenAttribute) {
         parent::setAttribute($key, $value);
     }
 }
开发者ID:EstebanJesus,项目名称:bancopedagogico,代码行数:10,代码来源:User.php

示例8: setAttribute

 /**
  * Set a given attribute on the model.
  *
  * @param  string $key
  * @param  mixed $value
  * @return $this
  */
 public function setAttribute($key, $value)
 {
     if (isset($this->mutations[$key])) {
         unset($this->mutations[$key]);
     }
     return parent::setAttribute($key, $value);
 }
开发者ID:NuclearCMS,项目名称:Hierarchy,代码行数:14,代码来源:NodeSourceExtension.php

示例9: save

 /**
  * Attach a model instance to the parent model.
  *
  * This adds the field_id value
  *
  * @param  \Illuminate\Database\Eloquent\Model  $model
  * @return \Illuminate\Database\Eloquent\Model
  */
 public function save(Model $model)
 {
     if ($this->fieldId) {
         $model->setAttribute($this->fieldKey, $this->fieldId);
     }
     return parent::save($model);
 }
开发者ID:czim,项目名称:laravel-pxlcms,代码行数:15,代码来源:HasOne.php

示例10: remove

 /**
  * Removes a model from this relationship type.
  */
 public function remove(Model $model, $sessionKey = null)
 {
     if ($sessionKey === null) {
         $options = $this->parent->getRelationDefinition($this->relationName);
         if (array_get($options, 'delete', false)) {
             $model->delete();
         } else {
             // Make this model an orphan ;~(
             $model->setAttribute($this->getPlainForeignKey(), null);
             $model->setAttribute($this->getPlainMorphType(), null);
             $model->save();
         }
     } else {
         $this->parent->unbindDeferred($this->relationName, $model, $sessionKey);
     }
 }
开发者ID:mechiko,项目名称:staff-october,代码行数:19,代码来源:MorphOneOrMany.php

示例11: saveAfter

 public function saveAfter(Model $child)
 {
     // this is what `$this->relation->save($child)` does
     // we inline it here to wrap the save() method
     $child->setAttribute($this->relation->getPlainForeignKey(), $this->relation->getParentKey());
     $result = DataSource::make($child)->save();
     return $result;
 }
开发者ID:tacone,项目名称:datasource,代码行数:8,代码来源:HasOneWrapper.php

示例12: toEloquentObject

 /**
  * Convert an instance to an eloquent model object.
  *
  * @param \Illuminate\Database\Eloquent\Model $eloquentModel
  * @param array $name
  * @return void
  */
 public function toEloquentObject(EloquentModel &$eloquentModel, $name)
 {
     // get model data
     $dict = ['mapping' => $eloquentModel->getMapping()];
     foreach ($dict['mapping']['embeddeds'][$name]['attributes'] as $attribute => $column) {
         $eloquentModel->setAttribute($column, $this->{$attribute});
     }
 }
开发者ID:proai,项目名称:laravel-datamapper,代码行数:15,代码来源:ValueObject.php

示例13: setAttribute

 /**
  * Override set attributes so we can check for empty strings.
  * @todo We need a different way to achieve this
  * @param string $key
  * @param mixed $value
  * @return $this
  */
 public function setAttribute($key, $value)
 {
     parent::setAttribute($key, $value);
     // TODO: Change the autogenerated stub
     if (isset($this->attributes[$key]) && is_string($this->attributes[$key]) && strlen($this->attributes[$key]) === 0) {
         $this->attributes[$key] = null;
     }
     return $this;
 }
开发者ID:despark,项目名称:ignicms,代码行数:16,代码来源:AdminModel.php

示例14: saveModel

 protected function saveModel(Eloquent $model, array $data)
 {
     $data = Arr::except($data, ['_token']);
     foreach ($data as $key => $value) {
         $model->setAttribute($key, $value);
     }
     $model->save();
     return $model;
 }
开发者ID:shopalicious,项目名称:support,代码行数:9,代码来源:SavableTrait.php

示例15: 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);
 }
开发者ID:salpakan,项目名称:salpakan,代码行数:15,代码来源:AddSlugAttribute.php


注:本文中的Illuminate\Database\Eloquent\Model::setAttribute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。