本文整理汇总了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);
}
}
示例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]);
}
示例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);
}
}
示例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);
}
示例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);
}
示例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());
}
}
示例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);
}
}
示例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);
}
示例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);
}
示例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);
}
}
示例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;
}
示例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});
}
}
示例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;
}
示例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;
}
示例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);
}