예제 #1
0
 /**
  * Delete an entity.
  *
  * @param  string   $id
  * @return ApiResponse
  */
 public function deleteOne(ElasticSearchIndexer $searchIndexer, $id)
 {
     $entity = $this->findOrFailEntity($id);
     $this->checkPermission(static::class . '@deleteOne', ['model' => $entity]);
     $searchIndexer->deleteOneAndReindexRelated($entity);
     return $this->getResponse()->noContent();
 }
예제 #2
0
 /**
  * Delete an entity.
  *
  * @param  string $id
  * @param bool|string $childId
  * @return ApiResponse
  * @throws \Exception
  */
 public function deleteOne($id, ElasticSearchIndexer $searchIndexer, $childId = false)
 {
     $parent = $this->findParentEntity($id);
     //If the child id is not passed in the url, fall back to the child id being the parent id (for the case where the relationship is HasOne with primary key being foreign parent id)
     if ($this->childIdCanFallbackToParent($childId, $parent)) {
         $childId = $parent->getKey();
     }
     $childModel = $this->findOrFailChildEntity($childId, $parent);
     $this->checkPermission(static::class . '@deleteOne', ['model' => $parent, 'children' => $childModel]);
     $searchIndexer->deleteOneAndReindexRelated($childModel);
     $parent->fireRevisionableEvent('deleteChild', [$childModel, $this->relationName]);
     return $this->getResponse()->noContent();
 }