本文整理汇总了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']]);
}
示例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);
}
示例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);
}
示例4: insertAndSetId
protected function insertAndSetId(Builder $query, $attributes)
{
$id = $query->insertGetId($attributes, $keyName = $this->getKeyName());
$this->setAttribute($keyName, $id);
}
示例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);
}
示例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);
}
示例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));
}
示例8: insertAndSetId
protected function insertAndSetId(\Illuminate\Database\Eloquent\Builder $query, $attributes)
{
$id = $query->insertGetId($attributes, $keyName = $this->getKeyName());
}