當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Builder::insertGetId方法代碼示例

本文整理匯總了PHP中Illuminate\Database\Eloquent\Builder::insertGetId方法的典型用法代碼示例。如果您正苦於以下問題:PHP Builder::insertGetId方法的具體用法?PHP Builder::insertGetId怎麽用?PHP Builder::insertGetId使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Illuminate\Database\Eloquent\Builder的用法示例。


在下文中一共展示了Builder::insertGetId方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: insertAndSetId

 /**
  * 重寫插入方法
  * param Builder $query
  * param $attributes
  */
 protected function insertAndSetId(Builder $query, $attributes)
 {
     //默認父ID
     $attributes[$this->treeField['parent_key']] = array_get($attributes, $this->treeField['parent_key'], 1);
     //初始化配置
     $this->treeInit(app('NestedSetsService'));
     //開啟事務,處理邊界
     DB::beginTransaction();
     //邊界處理,返回修改值
     $attributes = $this->nestend->insert($attributes[$this->treeField['parent_key']], $attributes, 'bottom');
     //保存數據
     $id = $query->insertGetId($attributes, $keyName = $this->getKeyName());
     //結果提交
     if ($attributes !== false && $id) {
         DB::commit();
     } else {
         DB::rollback();
         return false;
     }
     //賦值
     $this->setAttribute($keyName, $id);
     $this->setAttribute($this->treeField['parent_key'], $attributes[$this->treeField['parent_key']]);
     $this->setAttribute($this->treeField['level_key'], $attributes[$this->treeField['level_key']]);
     $this->setAttribute($this->treeField['left_key'], $attributes[$this->treeField['left_key']]);
     $this->setAttribute($this->treeField['right_key'], $attributes[$this->treeField['right_key']]);
 }
開發者ID:zsping1989,項目名稱:margin-tree,代碼行數:31,代碼來源:TreeModel.php

示例2: insertGetId

 /**
  * Insert a new record and get the value of the primary key.
  *
  * @param  array   $values
  * @param  string  $sequence
  * @return int
  */
 public function insertGetId(array $values, $sequence = null)
 {
     // Intercept operations on embedded models and delegate logic
     // to the parent relation instance.
     if ($relation = $this->model->getParentRelation()) {
         $relation->performInsert($this->model, $values);
         return $this->model->getKey();
     }
     return parent::insertGetId($values, $sequence);
 }
開發者ID:errietta,項目名稱:laravel-mongodb,代碼行數:17,代碼來源:Builder.php

示例3: insertAndSetId

 /**
  * Insert the given attributes and set the ID on the model.
  *
  * @param  \Illuminate\Database\Eloquent\Builder  $query
  * @param  array  $attributes
  * @return void
  */
 protected function insertAndSetId(Builder $query, $attributes)
 {
     $keyName = $this->getKeyName();
     // uuid management
     if ($this->uuid) {
         $id = uuid();
         $attributes[$keyName] = $id;
         $query->insert($attributes);
         // auto increment
     } else {
         $id = $query->insertGetId($attributes, $keyName);
     }
     $this->setAttribute($keyName, $id);
 }
開發者ID:frenchfrogs,項目名稱:framework,代碼行數:21,代碼來源:Model.php

示例4: insertAndSetId

 protected function insertAndSetId(Builder $query, $attributes)
 {
     $id = $query->insertGetId($attributes, $keyName = $this->getKeyName());
     $this->setAttribute($keyName, $id);
 }
開發者ID:devhrmx,項目名稱:kraken,代碼行數:5,代碼來源:compiled.php

示例5: insertAndSetId

 /**
  * Insert the given attributes and set the ID on the model.
  *
  * @param  \Illuminate\Database\Eloquent\Builder $query
  * @param  array $attributes
  * @return int|void
  */
 protected function insertAndSetId(Builder $query, $attributes)
 {
     if ($binaries = $this->wrapBinary($attributes)) {
         $id = $query->getQuery()->insertLob($attributes, $binaries, $keyName = $this->getKeyName());
     } else {
         $id = $query->insertGetId($attributes, $keyName = $this->getKeyName());
     }
     $this->setAttribute($keyName, $id);
 }
開發者ID:JFSolorzano,項目名稱:multiauth,代碼行數:16,代碼來源:OracleEloquent.php

示例6: insertAndSetId

 /**
  * Insert the given attributes and set the ID on the model.
  *
  * @param  \Illuminate\Database\Eloquent\Builder  $query
  * @param  array  $attributes
  * @return void
  */
 protected function insertAndSetId(Builder $query, $attributes)
 {
     $query->insertGetId($attributes);
 }
開發者ID:sebwas,項目名稱:laravel-eloquent-compound-keys,代碼行數:11,代碼來源:CompoundKeys.php

示例7: insertAndSetId

 /**
  * Insert the given attributes and set the ID on the model. Overrides
  * Model::insertAndSetID to set the guid column from the id.
  *
  * @param  \Illuminate\Database\Eloquent\Builder  $query
  * @param  array  $attributes
  * @return void
  */
 protected function insertAndSetId(Builder $query, $attributes)
 {
     $id = $query->insertGetId($attributes, $keyName = $this->getKeyName());
     $this->setAttribute($keyName, $id);
     // We have to cheat a bit and use $wpdb to perform a new update to set
     // the post's GUID.
     global $wpdb;
     $wpdb->update($wpdb->posts, array('guid' => get_permalink($id)), array('ID' => $id));
 }
開發者ID:ithinkdancan,項目名稱:framework,代碼行數:17,代碼來源:PostModel.php

示例8: insertAndSetId

 protected function insertAndSetId(\Illuminate\Database\Eloquent\Builder $query, $attributes)
 {
     $id = $query->insertGetId($attributes, $keyName = $this->getKeyName());
 }
開發者ID:monicajimenez,項目名稱:weas,代碼行數:4,代碼來源:EASRequest.php


注:本文中的Illuminate\Database\Eloquent\Builder::insertGetId方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。