https://github.com/ayoub-amzil/soft-delete-logger
Log soft deletes and restore actions on Eloquent models with user tracking in Laravel.
https://github.com/ayoub-amzil/soft-delete-logger
audit database laravel logs php softdelete
Last synced: 4 months ago
JSON representation
Log soft deletes and restore actions on Eloquent models with user tracking in Laravel.
- Host: GitHub
- URL: https://github.com/ayoub-amzil/soft-delete-logger
- Owner: ayoub-amzil
- License: mit
- Created: 2025-07-26T16:44:39.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2025-07-26T17:02:47.000Z (10 months ago)
- Last Synced: 2025-07-26T21:30:43.166Z (10 months ago)
- Topics: audit, database, laravel, logs, php, softdelete
- Language: PHP
- Homepage: https://packagist.org/packages/ayoub-amzil/soft-delete-logger
- Size: 4.88 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Soft Delete Logger
Log every soft delete and restore action on your Eloquent models β including the authenticated user who performed it.
## π¦ Installation
```
composer require ayoub-amzil/soft-delete-logger
```
## π οΈ Setup
### 1. Publish the migration
```
php artisan vendor:publish --tag=soft-delete-logger-migrations
```
Then migrate:
```
php artisan migrate
```
### 2. Add the trait to your model
```php
use AyoubAmzil\SoftDeleteLogger\Traits\LogsSoftDeletes;
class Product extends Model
{
use SoftDeletes, LogsSoftDeletes;
}
```
Thatβs it!
## π What it logs
Whenever a model is soft-deleted or restored, it logs:
- `model`: Class name of the model
- `model_id`: The ID of the deleted/restored record
- `user_id`: The ID of the currently authenticated user (or `null` if not logged in)
- `action`: Either `soft_deleted` or `restored`
- `timestamps`: When the action happened
## π Log Table Example
| id | model | model_id | user_id | action | created_at |
| --- | --------------- | -------- | ------- | ------------ | ---------- |
| 1 | App\Models\Post | 42 | 1 | soft_deleted | ... |
| 2 | App\Models\Post | 42 | 1 | restored | ... |
## β
Compatibility
- Laravel 10+
- Works with any model using `SoftDeletes`
## π License
[MIT](LICENSE)