Beispiel #1
0
 /**
  * 重写插入方法
  * 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']]);
 }
Beispiel #2
0
 /**
  * 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);
 }
Beispiel #3
0
 /**
  * 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);
 }
Beispiel #4
0
 protected function insertAndSetId(Builder $query, $attributes)
 {
     $id = $query->insertGetId($attributes, $keyName = $this->getKeyName());
     $this->setAttribute($keyName, $id);
 }
 /**
  * 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);
 }
 /**
  * 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);
 }
Beispiel #7
0
 /**
  * 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));
 }
Beispiel #8
0
 protected function insertAndSetId(\Illuminate\Database\Eloquent\Builder $query, $attributes)
 {
     $id = $query->insertGetId($attributes, $keyName = $this->getKeyName());
 }