Skip to content

Commit

Permalink
Replaces deleteChild method with fireRevisionableEvent()
Browse files Browse the repository at this point in the history
  • Loading branch information
artstorm committed Sep 7, 2015
1 parent a2f7d8f commit a4537e5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
3 changes: 2 additions & 1 deletion api/app/Http/Controllers/ChildEntityController.php
Expand Up @@ -224,7 +224,8 @@ public function deleteOne($id, $childId)
$model = $this->findParentEntity($id);
$childModel = $this->findOrFailChildEntity($childId, $model);

$model->deleteChild($childModel, $this->relationName);
$childModel->delete();
$model->fireRevisionableEvent('deleteChild', [$childModel, $this->relationName]);

return $this->getResponse()->noContent();
}
Expand Down
6 changes: 3 additions & 3 deletions api/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 10 additions & 6 deletions api/src/Model/Model/BaseModel.php
Expand Up @@ -337,16 +337,20 @@ public function save(array $options = [])
}

/**
* Delete child model from the database.
* Fires an event for RevisionableTrait.
*
* @param Model $model
* @param string $relation
* @param string $event
* @param array $payload
* @param bool $halt
*
* @return bool|null
* @return mixed
*/
public function deleteChild(Model $model, $relation)
public function fireRevisionableEvent($event, array $payload, $halt = true)
{
return $model->delete();
$event = "eloquent.{$event}: ".get_class($this);
$method = $halt ? 'until' : 'fire';

return static::$dispatcher->$method($event, array_merge([$this], $payload));
}

/**
Expand Down

0 comments on commit a4537e5

Please sign in to comment.