Skip to content

Commit

Permalink
Added destroyBy() method in Abstract Repo
Browse files Browse the repository at this point in the history
  • Loading branch information
micheleangioni committed Dec 28, 2015
1 parent 37dcf79 commit 7c413d3
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/MicheleAngioni/Support/Repos/AbstractEloquentRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -360,17 +360,28 @@ public function updateOrCreateBy(array $where, array $inputs = [])
public function destroy($id)
{
$model = $this->model->findOrFail($id);

return $model->delete();
}

public function destroyFirstBy(array $where)
{
$where = $this->purifyInputs($where);

$model = $this->firstOrFailBy($where);

return $model->delete();
}

public function destroyBy(array $where)
{
$query = $this->make();

foreach($where as $key => $value) {
$query = $query->where($key, '=', $value);
}

return $query->delete();
}

public function truncate()
{
return $this->model->truncate();
Expand Down

0 comments on commit 7c413d3

Please sign in to comment.