Skip to content

Commit

Permalink
take care of soft deletes (#14)
Browse files Browse the repository at this point in the history
* soft deleting
  • Loading branch information
julianstark999 authored Aug 2, 2021
1 parent 7abc5d8 commit ca98395
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes to `laravel-model-iid` will be documented in this file

## 0.1.1 - 2021-08-02
### added
- take care of soft deleting

## 0.1.0 - 2021-03-04
### added
- now using [Spatie Laravel Package Tools](https://github.com/spatie/laravel-package-tools)
Expand Down
7 changes: 6 additions & 1 deletion src/Traits/HasIidColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace JulianStark999\LaravelModelIid\Traits;

use Exception;
use Illuminate\Database\Eloquent\Builder;
use JulianStark999\LaravelModelIid\Exceptions\SchemaDoesNotHasIidColumn;

trait HasIidColumn
Expand All @@ -25,7 +26,11 @@ protected static function boot(): void
return;
}

$latestModel = $model->where($model->iidColumn, '=', $model[$model->iidColumn])
$latestModel = $model->when(
method_exists($model, 'forceDelete'),
fn (Builder $query) => $query->whereNull('deleted_at')->orWhereNotNull('deleted_at')
)
->where($model->iidColumn, '=', $model[$model->iidColumn])
->where('iid', '!=', 'NULL')
->orderBy('iid', 'DESC')
->first();
Expand Down

0 comments on commit ca98395

Please sign in to comment.