saveObjects() public method

Override the content of several objects.
public saveObjects ( array $objects, string $objectIDKey = 'objectID' ) : mixed
$objects array contains an array of objects to update (each object must contains a objectID attribute)
$objectIDKey string
return mixed
Ejemplo n.º 1
0
 public function it_adds_multiple_searchable_objects_to_the_search_index(\AlgoliaSearch\Index $index, Searchable $searchableObject)
 {
     $searchableObjects = [$searchableObject];
     $objects = [];
     $objects[] = array_merge($this->searchableBody, ['objectID' => $this->searchableType . '-' . $this->searchableId]);
     $index->saveObjects($objects)->shouldBeCalled();
     $this->upsertToIndex($searchableObjects);
 }
Ejemplo n.º 2
0
 /**
  * Add or update the given searchable subject or array of subjects or Traversable object containing subjects.
  *
  * @param Searchable|array|Traversable $subject
  */
 public function upsertToIndex($subject)
 {
     if ($subject instanceof Searchable) {
         $subject = [$subject];
     }
     if (is_array($subject) || $subject instanceof Traversable) {
         $searchIndexPayload = collect($subject)->each(function ($item) {
             if (!$item instanceof Searchable) {
                 throw new InvalidArgumentException();
             }
         })->map(function ($item) {
             return array_merge($item->getSearchableBody(), ['objectID' => $this->getAlgoliaId($item)]);
         })->toArray();
         $this->index->saveObjects($searchIndexPayload);
         return;
     }
     throw new InvalidArgumentException('Subject must be a searchable or array of searchables');
 }