当前位置: 首页>>代码示例>>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;未经允许,请勿转载。