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


PHP Model::update方法代码示例

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


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

示例1: update

 /**
  * 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);
 }
开发者ID:artissant,项目名称:stock,代码行数:14,代码来源:UserRepository.php

示例2: update

 /**
  * 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;
 }
开发者ID:christiannwamba,项目名称:laravel-site,代码行数:13,代码来源:BaseModel.php

示例3: update

 /**
  * 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;
 }
开发者ID:php-soft,项目名称:laravel-shopping-cart,代码行数:32,代码来源:Product.php

示例4: inlineUpdate

 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;
 }
开发者ID:procoders,项目名称:admin,代码行数:31,代码来源:ModelRepository.php

示例5: update

 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);
 }
开发者ID:ixudra,项目名称:imageable,代码行数:8,代码来源:Image.php

示例6: updateModel

 /**
  * @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;
 }
开发者ID:draperstudio,项目名称:eloquent-repositories,代码行数:16,代码来源:CrudlTrait.php

示例7: update

 /**
  * @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;
 }
开发者ID:rappasoft,项目名称:laravel-5-boilerplate,代码行数:13,代码来源:BaseRepository.php

示例8: update

 /**
  * 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();
 }
开发者ID:wyrover,项目名称:laravel-users,代码行数:14,代码来源:RoutePermission.php

示例9: update

 /**
  * 执行更新操作
  *
  * @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('修改失败,请稍后再试');
 }
开发者ID:netxinyi,项目名称:meigui,代码行数:16,代码来源:ResourceTrait.php

示例10: update

 /**
  * 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);
 }
开发者ID:rtmatt,项目名称:rtclientmanager,代码行数:12,代码来源:ServiceMonth.php

示例11: update

 /**
  * 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);
 }
开发者ID:emilmoe,项目名称:guardian,代码行数:17,代码来源:Role.php

示例12: update

 /**
  * 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;
 }
开发者ID:emtudo,项目名称:laravel-shopping-cart,代码行数:16,代码来源:Product.php

示例13: update

 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;
 }
开发者ID:emmanuelsf,项目名称:xdrawerl,代码行数:11,代码来源:Container.php

示例14: update

 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);
 }
开发者ID:Carlsson87,项目名称:lumen,代码行数:11,代码来源:Workout.php

示例15: update

 /**
  * 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);
 }
开发者ID:GeeH,项目名称:slim-bookshelf,代码行数:19,代码来源:Author.php


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