update() public method

Update the model in the database.
public update ( array $attributes = [], array $options = [] ) : boolean
$attributes array
$options array
return boolean
Esempio n. 1
0
 /**
  * Update a user.
  *
  * @param Model $item
  * @param array $data
  * @return bool|int
  */
 public function update(Model $item, array $data)
 {
     if (isset($data['password'])) {
         $data['password'] = bcrypt($data['password']);
     }
     return $item->update($data);
 }
Esempio n. 2
0
 /**
  * Update an existing model.
  * @param  array $input
  * @throws Exception
  * @return mixed
  */
 public function update(array $input = [])
 {
     $this->beforeUpdate($input);
     $return = parent::update($input);
     $this->afterUpdate($input, $return);
     return $return;
 }
Esempio n. 3
0
 /**
  * Update the model in the database.
  *
  * @param  array  $attributes
  * @return bool|int
  */
 public function update(array $attributes = [])
 {
     if (isset($attributes['alias']) && empty($attributes['alias'])) {
         $name = $this->name;
         if (isset($attributes['name'])) {
             $name = $attributes['name'];
         }
         $attributes['alias'] = Str::slug($name) . '-' . Uuid::generate(4);
     }
     if (isset($attributes['galleries'])) {
         if (empty($attributes['galleries'])) {
             $attributes['galleries'] = [];
         }
         $attributes['galleries'] = json_encode($attributes['galleries']);
     }
     if (isset($attributes['attributes'])) {
         if (empty($attributes['attributes'])) {
             $attributes['attributes'] = [];
         }
         $attributes['attributes'] = json_encode($attributes['attributes']);
     }
     if (!parent::update($attributes)) {
         throw new Exception('Cannot update product.');
     }
     return $this;
 }
Esempio n. 4
0
 public function inlineUpdate($id)
 {
     $this->instance = $this->find($id);
     if (empty($this->instance)) {
         return false;
     }
     $data = $this->request->all();
     $updated = false;
     if (method_exists($this->instance, 'getRepository')) {
         $repository = $this->instance->getRepository();
         if (method_exists($repository, 'inlineSave')) {
             if ($repository->inlineSave($data)) {
                 $updated = true;
             } else {
                 return false;
             }
         }
     }
     if ($updated == false) {
         $fillableFields = $this->instance->getFillable();
         foreach ($data as $key => $value) {
             if (in_array($key, $fillableFields)) {
                 $this->instance->{$key} = $value;
             }
         }
         if ($this->instance->update()) {
             $updated = true;
         }
     }
     return $updated;
 }
Esempio n. 5
0
 public function update(array $attributes = array(), array $options = array())
 {
     if (array_key_exists('file', $attributes)) {
         $this->deleteFile();
         $this->uploadFile($attributes['file'], $attributes['file_name']);
     }
     parent::update($attributes, $options);
 }
 /**
  * @param Model $model
  * @param array $data
  *
  * @throws RepositoryException
  *
  * @return Model
  */
 public function updateModel(Model $model, array $data)
 {
     if (!$model->update($data)) {
         throw new RepositoryException('Could not be saved');
     }
     $this->makeModel();
     return $model;
 }
 /**
  * @param Model $model
  * @param array $input
  * @return bool
  */
 public function update(Model $model, array $input)
 {
     $updated = $model->update($input);
     if ($updated) {
         app('cache')->flush();
     }
     return $updated;
 }
Esempio n. 8
0
 /**
  * Update permissions and roles of a route.
  *
  * @param  array  $attributes
  * @return bool|int
  */
 public function update(array $attributes = [])
 {
     if (!parent::update($attributes)) {
         throw new Exception('Cannot update category.');
         // @codeCoverageIgnore
     }
     return $this->fresh();
 }
Esempio n. 9
0
 /**
  * 执行更新操作
  *
  * @param \Illuminate\Database\Eloquent\Model $model
  *
  * @return mixed
  */
 public function update(Model $model)
 {
     $this->validateUpdate();
     $form = $this->request()->all();
     if ($model->update($form)) {
         return $this->success('保存成功', $model);
     }
     return $this->error('修改失败,请稍后再试');
 }
Esempio n. 10
0
 /**
  * If a future month is being set to 0, set the value to null instead of 0
  */
 public function update(array $attributes = [], array $options = [])
 {
     if (array_key_exists('hours_used', $attributes) && $attributes['hours_used'] == 0) {
         if ($this->getStartDate() > \Carbon\Carbon::now()) {
             $attributes['hours_used'] = null;
         }
     }
     parent::update($attributes);
 }
Esempio n. 11
0
 /**
  * Update the model in the database.
  *
  * @param array $attributes
  * @param array $options
  * @return bool|int
  */
 public function update(array $attributes = [], array $options = [])
 {
     if (Guardian::hasClients()) {
         $attributes[Guardian::getClientColumn()] = Guardian::getClientId();
     }
     if ($this->locked) {
         return false;
     }
     return parent::update($attributes, $options);
 }
Esempio n. 12
0
 /**
  * Update the model in the database.
  *
  * @param  array  $attributes
  * @return bool|int
  */
 public function update(array $attributes = [])
 {
     if (!empty($attributes['galleries'])) {
         $attributes['galleries'] = json_encode($attributes['galleries']);
     }
     if (!parent::update($attributes)) {
         throw new Exception('Cannot update product.');
     }
     return $this;
 }
Esempio n. 13
0
 public function update(array $data = [])
 {
     unset($data['_method'], $data['_token']);
     if (parent::update($data)) {
         unset($data['color']);
         if (Element::where('element_data_id', $this->id)->update($data)) {
             return true;
         }
     }
     return false;
 }
Esempio n. 14
0
 public function update(array $attributes = [])
 {
     parent::update($attributes);
     $instances = collect();
     foreach ($attributes['instances'] as $instance) {
         $instance['date'] = $attributes['date'];
         $instances->push($this->instances()->updateOrCreate(array_merge(['id' => 0], array_only($instance, ['id'])), $instance));
     }
     $this->instances()->whereNotIn('id', $instances->pluck('id')->all())->delete();
     return $this->setRelation('instances', $instances);
 }
Esempio n. 15
0
 /**
  * Update author with new data
  *
  * @param  arrray $data
  * @return null
  */
 public function update(array $data = [])
 {
     $validator = $this->getValidator($data);
     if (!$validator->validate()) {
         $messages = [];
         foreach ($validator->errors() as $fieldName => $errors) {
             $messages[] = current($errors);
         }
         $message = implode("\n", $messages);
         throw new \Exception($message);
     }
     return parent::update($data);
 }
Esempio n. 16
0
 /**
  * Update the model in the database.
  *
  * @param  array  $attributes
  * @return bool|int
  */
 public function update(array $attributes = [])
 {
     if (isset($attributes['alias']) && empty($attributes['alias'])) {
         $title = $this->title;
         if (isset($attributes['title'])) {
             $title = $attributes['title'];
         }
         $attributes['alias'] = Str::slug($title);
     }
     if (!parent::update($attributes)) {
         throw new Exception('Cannot update article.');
     }
     return $this;
 }
Esempio n. 17
0
 /**
  * Update the model in the database.
  *
  * @param  array  $attributes
  * @return bool|int
  */
 public function update(array $attributes = [])
 {
     if (isset($attributes['password'])) {
         $attributes['password'] = bcrypt($attributes['password']);
     }
     if (!parent::update($attributes)) {
         throw new Exception('Cannot update user.');
         // @codeCoverageIgnore
     }
     if (!parent::update($attributes)) {
         throw new Exception('Cannot update user.');
         // @codeCoverageIgnore
     }
     return $this->fresh();
 }
Esempio n. 18
0
 public function update(array $attributes = [])
 {
     //There's one user and they're not the owner of the site yet.
     //Or the owner is giving ownership to another user.
     if (array_key_exists('owner', $attributes)) {
         if (count(User::all()) == 1 && $this->owner == 0 || $this->owner) {
             $attributes['owner'] = true;
         } else {
             $attributes['owner'] = false;
         }
     } else {
         if ($this->owner) {
             $attributes['owner'] = true;
         } else {
             $attributes['owner'] = false;
         }
     }
     parent::update($attributes);
 }
 /**
  * Update an entity with the given attributes and persist it
  *
  * @param Model $entity
  * @param array $data
  * @return bool
  */
 public function update(Model $entity, array $data)
 {
     $result = $entity->update($data);
     if ($result) {
         event(new RepositoryEntityEvent('update', $this));
     }
     return $result;
 }
 /**
  * Update a model given a model and an array of new attributes
  *
  * @param Model $model
  * @param array $newAttributes
  * @return mixed
  * @throws UpdateFailedRepositoryException
  */
 public function update(Model $model, array $newAttributes)
 {
     $results = $model->update($newAttributes);
     if (!$results) {
         throw new UpdateFailedRepositoryException();
     }
     return $model;
 }
 public function update($data = array())
 {
     $this->model->update($this->match($data));
     return $this;
 }
Esempio n. 22
0
 /**
  * Processes updating the specified SKU
  * record with the specified code.
  *
  * @param Model  $sku
  * @param string $code
  *
  * @return mixed|bool
  */
 protected function processSkuUpdate(Model $sku, $code)
 {
     $this->dbStartTransaction();
     try {
         if ($sku->update(compact('code'))) {
             $this->dbCommitTransaction();
             return $sku;
         }
     } catch (\Exception $e) {
         $this->dbRollbackTransaction();
     }
     return false;
 }
 /**
  * Update node.
  *
  * @param  int $node
  * @return \Illuminate\Database\Eloquent\Model
  * 
  * @throws \Langaner\MaterializedPath\Exceptions\NodeNotFoundException
  */
 public function updateNode(Model $node)
 {
     if (!$node) {
         throw new NodeNotFoundException('Node doesnt exist');
     }
     $parent = $this->newQuery()->find($node->parent_id);
     if ($parent === null) {
         $parent = $this->createRootObject();
     }
     $node->sibling()->where($this->getColumnTreeOrder(), '>=', $node->getTreeOrder())->where('id', '!=', $node->id)->increment($this->getColumnTreeOrder());
     $children = $node->childrenByDepth()->get();
     if ($parent->getTreeRealPath() === '') {
         $path = $this->separator . '0' . $this->separator;
         if ($this->useRealPath()) {
             $realPath = $node->{$this->columnAlias};
         }
     } else {
         $path = str_replace($node->getTreePath(), $parent->getTreePath() . $parent->id . $this->separator, $node->getTreePath());
         if ($this->useRealPath()) {
             $realPath = str_replace($node->getTreeRealPath(), $parent->getTreeRealPath() . $this->separator . $node->{$this->columnAlias}, $node->getTreeRealPath());
         }
     }
     $fields = [$node->getColumnTreePath() => str_replace('//', '/', $path), $node->getColumnTreePid() => $parent->getKey(), $node->getColumnTreeOrder() => $node->getTreeOrder(), $node->getColumnTreeDepth() => count($this->getExplodedPath($path)) - 1];
     if ($this->useRealPath()) {
         $fields[$node->getColumnTreeRealPath()] = $realPath;
     }
     $node->update($fields);
     foreach ($children as $child) {
         $path = str_replace($child->getTreePath(), $node->getTreePath() . $node->getKey() . $this->separator, $child->getTreePath());
         $fields = [$child->getColumnTreePath() => $path];
         if ($this->useRealPath()) {
             $realPath = str_replace($child->getTreeRealPath(), $node->getTreeRealPath() . $this->separator . $child->{$this->columnAlias}, $child->getTreeRealPath());
             $fields[$node->getColumnTreeRealPath()] = $realPath;
         }
         $child->update($fields);
     }
     return $this;
 }
Esempio n. 24
0
 public function update(Model $notification, $attributes)
 {
     return $notification->update($attributes);
 }
Esempio n. 25
0
 /**
  * @param $data
  * @return bool|int
  */
 public function update($data)
 {
     return $this->model->update($data);
 }
Esempio n. 26
0
 public function update(Model $address, $attributes)
 {
     return $address->update($attributes);
 }
Esempio n. 27
0
 public function update(array $attributes = [], array $options = [])
 {
     $this->clearEntityCacheByTableColumns();
     $this->clearEntityCacheById();
     return parent::update($attributes, $options);
 }
Esempio n. 28
0
 /**
  * to update main model
  * 
  * @return bool
  */
 protected function updateMainModel()
 {
     $result = $this->updatedMainModel->update($this->picker->getNonMultilangToArray());
     $this->fireOnCRUD('updating');
     return is_int($result) && $result >= 1 ? true : $result;
 }
Esempio n. 29
0
 /**
  * Update user with validated data.
  *
  * @author Casper Rasmussen <*****@*****.**>
  *
  * @param  \Illuminate\Database\Eloquent\Model $user
  * @param  array                               $data
  * @return \Illuminate\Database\Eloquent\Model
  * @throws \Nodes\Database\Exceptions\SaveFailedException
  */
 public function updateUser(Model $user, array $data)
 {
     // If no password is set, we'll need to
     // remove 'password' and 'password_repeat' from $data
     // before we start filling, so we don't override it.
     if (empty($data['password'])) {
         unset($data['password'], $data['password_repeat']);
     }
     // Fill with new data
     $user->update($data);
     // Add image to user if one has been uploaded
     if (!empty($data['image']) && $data['image'] instanceof UploadedFile) {
         try {
             $imagePath = assets_add_uploaded_file($data['image'], 'backend_user_images');
             $user->update(['image' => $imagePath]);
         } catch (Exception $e) {
             // Do nothing
         }
     } elseif (empty($data['file_picker_file_name']) && !empty($user->image)) {
         // Remove profile image
         $user->update(['image' => null]);
     }
     // Return
     return $user;
 }
 /**
  * Update device type.
  * @param  Requests\Request $request    [description]
  * @param  \App\DeviceType  $deviceType [description]
  * @return [type]                       [description]
  */
 public function update(Requests\Request $request, Model $deviceType)
 {
     return $deviceType->update($request->all());
 }