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