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


PHP Model::save方法代码示例

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


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

示例1: insert

 /**
  * @param array $data
  * @return bool
  */
 public function insert(array $data = [])
 {
     $this->source->fill($data);
     if ($this->source->save()) {
         return $this->source->getKey();
     }
     return false;
 }
开发者ID:cocona,项目名称:core,代码行数:12,代码来源:EloquentResource.php

示例2: delete

 /**
  * Delete this customer credit card in the billing gateway.
  *
  * @return Creditcard
  */
 public function delete()
 {
     if (!$this->model->readyForBilling()) {
         return $this;
     }
     $this->card->delete();
     $cards = array();
     foreach ($this->model->billing_cards as $c) {
         if (Arr::get($c, 'id') != $this->id) {
             $cards[] = $c;
         }
     }
     $this->model->billing_cards = $cards;
     $this->model->save();
     // Refresh all subscription records that referenced this card.
     if ($subscriptions = $this->model->subscriptionModelsArray()) {
         foreach ($subscriptions as $subscription) {
             if ($subscription->billingIsActive() && $subscription->billing_card == $this->id) {
                 $subscription->subscription()->refresh();
             }
         }
     }
     $this->info = array('id' => $this->id);
     return $this;
 }
开发者ID:autocar,项目名称:laravel-billing,代码行数:30,代码来源:Creditcard.php

示例3: updated

 public function updated(Model $model)
 {
     if ($model->isDirty('parent_id')) {
         /**
          * 同步Original数据,是為了清除parent_id的dirty狀態
          */
         $model->syncOriginal();
         $tableName = $model->getTable();
         $oldNode = $model->getOriginal('node');
         if (0 < $model->parent_id) {
             /**
              * @var Model  $parent
              */
             $parent = $model->find($model->parent_id);
             $model->node = $parent->node . $model->id . self::SEPARATOR;
             $model->save();
             //取出原来的level
             $originalLevel = Cache::pull('node-category-original-level-' . $model->id);
             //计算新level与原来的level的差值
             $i = $model->level - $originalLevel;
             DB::table($tableName)->where('node', 'like', $oldNode . '%')->where('id', '<>', $model->id)->update(['level' => DB::raw("level + {$i}"), 'node' => DB::raw("REPLACE(`node`, '{$oldNode}', '{$model->node}')")]);
         } else {
             //修改為頂級分類
             $model->level = 1;
             $model->node = self::SEPARATOR . $model->id . self::SEPARATOR;
             $model->save();
             DB::table($tableName)->where('node', 'like', $oldNode . '%')->where('id', '<>', $model->id)->update(['level' => DB::raw("level - {$model->level}"), 'node' => DB::raw("CONCAT('{$model->node}', `id`, ',')")]);
         }
     }
 }
开发者ID:vergil-lai,项目名称:node-categoires,代码行数:30,代码来源:Observer.php

示例4: update

 /**
  * Template method for updating a record in storage
  * 
  * @param  int $id   
  * @param  array  $fields
  * @return bool       
  */
 public function update($id, array $fields)
 {
     //caching the updated model
     $this->model = $this->findById($id);
     $this->fillData($fields);
     return $this->model->save($fields);
 }
开发者ID:aamirchaudhary,项目名称:guardian,代码行数:14,代码来源:BaseRepository.php

示例5: save

 public function save(array $options = array())
 {
     if (!isset($this->id)) {
         $this->ordem = Tarefa::orderBy('ordem', 'DESC')->first()->ordem + 1;
     }
     return parent::save($options);
 }
开发者ID:WallasFaria,项目名称:tarefas,代码行数:7,代码来源:Tarefa.php

示例6: save

 public function save(array $options = array())
 {
     $filename = $this->createBill($this->course()->getResults());
     $this->amount = $this->course()->getResults()->participantNum;
     $this->filename = $filename;
     parent::save($options);
 }
开发者ID:salvomulas,项目名称:angryproton,代码行数:7,代码来源:Bill.php

示例7: save

 /**
  * 存储操作
  *
  * 存储时尝试先存储 Relation ,再存储 Model ,任一失败则回滚
  *
  * @param array $options
  * @return bool
  */
 public function save($options = []) : bool
 {
     \DB::beginTransaction();
     try {
         $failed = $this->saveRelations() === false || $this->original->save() === false;
         if ($failed) {
             \DB::rollBack();
             return false;
         }
         \DB::commit();
         return true;
     } catch (\Throwable $e) {
         \DB::rollBack();
         return false;
     }
 }
开发者ID:wutongwan,项目名称:laravel-lego,代码行数:24,代码来源:EloquentRow.php

示例8: createMainModel

 /**
  * to create main model
  * 
  * @return boolean
  */
 protected function createMainModel(Model $model)
 {
     $post = $this->picker->getNonMultilangToArray();
     $this->createdMainModel = $model->create($post);
     $this->fireOnCRUD('creating');
     return $this->createdMainModel->save();
 }
开发者ID:muratsplat,项目名称:multilang,代码行数:12,代码来源:MultiLang.php

示例9: save

 /**
  * Overriding base save to check first if status is sold and if so, if quantity sold = quantity.
  *
  * @param  array  $options
  * @return bool
  */
 public function save(array $options = [])
 {
     if ($this->product_status == 3) {
         $this->quantity_sold = $this->quantity;
     }
     return parent::save($options);
 }
开发者ID:aducworth,项目名称:inventory,代码行数:13,代码来源:Product.php

示例10: refresh

 /**
  * Refresh local model data for this customer.
  *
  * @return Billing
  */
 public function refresh()
 {
     $info = array();
     if ($this->customer) {
         try {
             $info = $this->customer->info();
         } catch (Exception $e) {
         }
     }
     if (!empty($info)) {
         $this->model->billing_id = $this->customer->id();
         $this->model->billing_discounts = $info['discounts'];
         $cards = array();
         foreach ($this->customer->cards() as $card) {
             $cards[] = $card->info();
         }
         $this->model->billing_cards = $cards;
     } else {
         $this->model->billing_id = null;
         $this->model->billing_cards = null;
         $this->model->billing_discounts = null;
     }
     $this->model->save();
     $this->info = $info;
     return $this;
 }
开发者ID:linkthrow,项目名称:laravel-billing,代码行数:31,代码来源:Billing.php

示例11: onCrudSaved

 /**
  * Seed the form with defaults that are stored in the session
  *
  * @param Model $model
  * @param CrudController $crudController
  */
 public function onCrudSaved(Model $model, CrudController $crudController)
 {
     $fb = $crudController->getFormBuilder();
     foreach ($fb->getElements() as $name => $element) {
         if (!$element instanceof FileElement) {
             continue;
         }
         if ($model instanceof File) {
             $file = $model;
         } else {
             $file = new File();
         }
         if ($uploaded = Input::file($name)) {
             // Save the file to the disk
             $uploaded->move(storage_path($element->getPath()), $uploaded->getClientOriginalName());
             // Update the file model with metadata
             $file->name = $uploaded->getClientOriginalName();
             $file->extension = $uploaded->getClientOriginalExtension();
             $file->size = $uploaded->getClientSize();
             $file->path = $element->getPath() . '/' . $uploaded->getClientOriginalName();
             $file->save();
             if (!$model instanceof File) {
                 $model->{$name} = $element->getPath() . '/' . $uploaded->getClientOriginalName();
                 $model->save();
             }
         }
     }
 }
开发者ID:boyhagemann,项目名称:uploads,代码行数:34,代码来源:SaveFileToDisk.php

示例12: save

 public function save(array $options = [])
 {
     if (!$this->exists) {
         $this->uid = $this->genNewUID();
     }
     return parent::save($options);
 }
开发者ID:tobymaxham,项目名称:kraut-newsletter,代码行数:7,代码来源:NewsletterList.php

示例13: save

 /**
  * Save the model to the database.
  *
  * @param  array  $options
  * @return bool
  */
 public function save(array $options = [])
 {
     $this->xh = Auth::user()->xh;
     $this->czsj = Carbon::now();
     $this->bz = isset($this->bz) ? $this->bz : '';
     return parent::save($options);
 }
开发者ID:rxfu,项目名称:student,代码行数:13,代码来源:Slog.php

示例14: save

 public function save(array $options = [])
 {
     if (!$this->exists && !$this->isDirty(static::CREATED_AT)) {
         $this->setCreatedAt($this->freshTimestamp());
     }
     return parent::save($options);
 }
开发者ID:Arthas91,项目名称:twohugs,代码行数:7,代码来源:SearchList.php

示例15: save

 public function save(array $options = [])
 {
     if ($this->relation) {
         $this->relation->save();
     }
     parent::save($options);
 }
开发者ID:Phrantiques,项目名称:toolbox-laravel,代码行数:7,代码来源:Entity.php


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