本文整理汇总了PHP中Illuminate\Database\Query\Builder::insert方法的典型用法代码示例。如果您正苦于以下问题:PHP Builder::insert方法的具体用法?PHP Builder::insert怎么用?PHP Builder::insert使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Database\Query\Builder
的用法示例。
在下文中一共展示了Builder::insert方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Construct Closet object with owner's uid.
*
* @param int $uid
*/
public function __construct($uid)
{
$this->uid = $uid;
$this->db = DB::table('closets');
// create a new closet if not exists
if (!$this->db->where('uid', $uid)->get()) {
$this->db->insert(['uid' => $uid, 'textures' => '']);
}
// load items from json string
$this->textures = json_decode($this->db->where('uid', $uid)->get()[0]->textures, true);
$this->textures = is_array($this->textures) ? $this->textures : [];
$textures_invalid = [];
// traverse items in the closet
foreach ($this->textures as $texture) {
$result = Texture::find($texture['tid']);
if ($result) {
// set user custom texture name
$result->name = $texture['name'];
// push instances of App\Models\Texture to the bag
if ($result->type == "cape") {
$this->textures_cape[] = $result;
} else {
$this->textures_skin[] = $result;
}
} else {
$textures_invalid[] = $texture['tid'];
continue;
}
}
// remove invalid textures from closet
foreach ($textures_invalid as $tid) {
$this->remove($tid);
}
unset($textures_invalid);
}
示例2: it_appends_events
/**
* @test
*/
public function it_appends_events()
{
$event = new PointsWereAdded(100);
$stream = new EventStream($event);
$eventData = ['aggregate_root_id' => 'BarId', 'type' => PointsWereAdded::class, 'payload' => ['amount' => '100']];
$this->db->table('events')->willReturn($this->queryBuilder);
$this->serializer->serialize($event)->willReturn(['amount' => '100']);
$this->queryBuilder->insert([$eventData])->willReturn(true);
$this->eventStore->append($stream);
}
示例3: insert
/**
* insert data
*
* @param array $args insert data
* @return bool
*/
public function insert(array $args)
{
if ($this->dynamic === false) {
return $this->query->insert($args);
}
$result = true;
if (count($insert = $this->filter($args, $this->schema())) > 0) {
$result = $this->query->insert($insert);
}
if ($this->proxy === true) {
// autoincrement 가 primary key 일 경우 처리 할 것은?
$this->getProxyManager()->insert($args);
}
return $result;
}
示例4: insert
/**
* Insert a new record into the database.
*
* @param array $values
* @return bool
* @static
*/
public static function insert($values)
{
return \Illuminate\Database\Query\Builder::insert($values);
}
示例5: insert
private function insert($data)
{
foreach (array_chunk($data, 500) as $chunk) {
$this->builder->insert($chunk);
}
}
示例6: batchInsert
/**
* @param \Illuminate\Database\Query\Builder $builder
* @param array $data
*/
protected function batchInsert(\Illuminate\Database\Query\Builder $builder, array $data)
{
$builder->getConnection()->transaction(function () use($builder, $data) {
// Batch in group of 250 entries to prevent "Too many SQL variables" SQL error
$insertBatchSize = 250;
$insertBatchCount = ceil(count($data) / $insertBatchSize);
for ($i = 0; $i < $insertBatchCount; ++$i) {
$insertedData = array_slice($data, $i * $insertBatchSize, $insertBatchSize);
$builder->insert($insertedData);
}
});
}
示例7: insert
/**
* Insert a new record into the database.
*
* @param array $values
*
* @return bool
*/
public function insert(array $values)
{
$result = parent::insert($values);
$this->handler->setBuilder($this)->setValues($values)->setSqlOperation('insert')->invalidateQuery('insert');
return $result;
}
示例8: insert
public function insert(array $values)
{
if ($this->needFlushCache()) {
// 清空表级缓存
$meta = $this->getMeta();
$meta->flush($this->db(), $this->model->table());
if (!is_array(reset($values))) {
$values = [$values];
}
$toClearIds = [];
foreach ($values as $value) {
$toClearIds[] = $value[$this->model->primaryKey()];
}
$toClearKeys = $this->buildRowCacheKey($toClearIds);
$this->getCache()->del(array_values($toClearKeys));
}
return parent::insert($values);
}