An open API service indexing awesome lists of open source software.

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.

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)