Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions src/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,18 @@

class Collection extends BaseCollection
{
public function addToIndex()
/**
* @var array
*/
protected $addToIndexResult;

/**
* @return bool
*/
public function addToIndex(): bool
{
if ($this->isEmpty()) {
return;
return true;
}

$instance = $this->first();
Expand All @@ -25,8 +33,18 @@ public function addToIndex()

$success = $query->insert($docs->all());

$this->addToIndexResult = $query->getQuery()->getInsertResult();

unset($docs);

return $success;
}

/**
* @return array|null
*/
public function getAddToIndexResult(): ?array
{
return $this->addToIndexResult;
}
}
19 changes: 17 additions & 2 deletions src/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class QueryBuilder extends BaseBuilder

protected $routing;

protected $insertResult;

/**
* All of the supported clause operators.
*
Expand Down Expand Up @@ -731,9 +733,9 @@ public function cursor()
*/
public function insert(array $values): bool
{
$result = $this->connection->insert($this->grammar->compileInsert($this, $values));
$this->insertResult = $this->connection->insert($this->grammar->compileInsert($this, $values));

return empty($result['errors']);
return empty($this->insertResult['errors']);
}

/**
Expand Down Expand Up @@ -767,6 +769,11 @@ public function delete($id = null): bool
return !empty($result['found']);
}

/**
* @param mixed $method
* @param mixed $parameters
* @return void
*/
public function __call($method, $parameters)
{
if (Str::startsWith($method, 'filterWhere')) {
Expand All @@ -776,6 +783,14 @@ public function __call($method, $parameters)
return parent::__call($method, $parameters);
}

/**
* @return array
*/
public function getInsertResult(): array
{
return array_column($this->insertResult['items'], 'index');
}

/**
* @return bool
*/
Expand Down