diff --git a/CHANGELOG.md b/CHANGELOG.md index 654bf6c..6f8bb67 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/src/Traits/HasIidColumn.php b/src/Traits/HasIidColumn.php index 2521513..07f2e7c 100644 --- a/src/Traits/HasIidColumn.php +++ b/src/Traits/HasIidColumn.php @@ -3,6 +3,7 @@ namespace JulianStark999\LaravelModelIid\Traits; use Exception; +use Illuminate\Database\Eloquent\Builder; use JulianStark999\LaravelModelIid\Exceptions\SchemaDoesNotHasIidColumn; trait HasIidColumn @@ -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();