Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ php artisan vendor:publish --provider "Prettus\Repository\Providers\RepositorySe
- update(array $attributes, $id)
- updateOrCreate(array $attributes, array $values = [])
- delete($id)
- forceDelete($id)
- deleteWhere(array $where)
- orderBy($column, $direction = 'asc');
- with(array $relations);
Expand Down Expand Up @@ -431,6 +432,12 @@ Delete entry in Repository
$this->repository->delete($id)
```

Force delete entry in Repository

```php
$this->repository->forceDelete($id)
```

Delete entry in Repository by multiple fields

```php
Expand Down
9 changes: 9 additions & 0 deletions src/Prettus/Repository/Contracts/RepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,15 @@ public function updateOrCreate(array $attributes, array $values = []);
*/
public function delete($id);

/**
* Force a hard delete on a soft deleted model to a entity in repository by id
*
* @param $id
*
* @return int
*/
public function forceDelete($id);

/**
* Order collection by a given column
*
Expand Down
29 changes: 29 additions & 0 deletions src/Prettus/Repository/Eloquent/BaseRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,35 @@ public function delete($id)
return $deleted;
}

/**
* Force a hard delete on a soft deleted model to a entity in repository by id
*
* @param $id
*
* @return int
*/
public function forceDelete($id)
{
$this->applyScope();

$temporarySkipPresenter = $this->skipPresenter;
$this->skipPresenter(true);

$model = $this->find($id);
$originalModel = clone $model;

$this->skipPresenter($temporarySkipPresenter);
$this->resetModel();

event(new RepositoryEntityDeleting($this, $model));

$deleted = $model->forceDelete();

event(new RepositoryEntityDeleted($this, $originalModel));

return $deleted;
}

/**
* Delete multiple entities by given criteria.
*
Expand Down