예제 #1
0
 public function detachAll(ElasticSearchIndexer $searchIndexer, $id)
 {
     $parent = $this->findParentEntity($id);
     $this->checkPermission(static::class . '@detachAll', ['model' => $parent]);
     $reindexItems = $searchIndexer->getAllItemsFromRelations($parent, [$this->relationName]);
     $this->getRelation($parent)->detach();
     // Reindex parent entity
     $searchIndexer->reindexOne($parent, []);
     // Reindex all detached entities
     $searchIndexer->reindexMany($reindexItems, []);
     return $this->getResponse()->noContent();
 }
예제 #2
0
 /**
  * Patch many entites.
  *
  * @param  Request  $request
  * @return ApiResponse
  */
 public function patchMany(Request $request, ElasticSearchIndexer $searchIndexer)
 {
     $requestCollection = $request->json()->all();
     $this->validateRequestCollection($requestCollection, $this->getModel(), true);
     $existingModels = $this->findOrFailCollection($requestCollection);
     $modelsCollection = $this->fillModels($this->getModel(), $existingModels, $requestCollection);
     $this->checkPermission(static::class . '@patchMany', ['model' => $existingModels]);
     $modelsCollection->each(function (BaseModel $model) {
         return $model->save();
     });
     $searchIndexer->reindexMany($modelsCollection);
     return $this->getResponse()->noContent();
 }
예제 #3
0
 /**
  * Patch many entites.
  *
  * @param string $id
  * @param  Request $request
  * @return ApiResponse
  */
 public function patchMany(Request $request, ElasticSearchIndexer $searchIndexer, $id)
 {
     $requestCollection = $request->json()->all();
     $this->validateRequestCollection($requestCollection, $this->getChildModel(), true);
     $parent = $this->findParentEntity($id);
     $existingModels = $this->findOrFailChildrenCollection($requestCollection, $parent);
     $childModels = $this->fillModels($this->getChildModel(), $existingModels, $requestCollection);
     $this->checkPermission(static::class . '@patchMany', ['model' => $parent, 'children' => $childModels]);
     $this->getRelation($parent)->saveMany($childModels);
     // Parent should be reindexed itself
     $searchIndexer->reindexOne($parent, []);
     // We need to reindex all items with relations
     $searchIndexer->reindexMany($childModels);
     return $this->getResponse()->noContent();
 }