當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。