Skip to content

Commit 48bf0dd

Browse files
committed
Refactor pruning logic and update documentation.
Updated the `prunable()` method to ensure no rows are returned when pruning is disabled. Enhanced README instructions for configuring pruning schedules across Laravel versions for better clarity.
1 parent 848d16f commit 48bf0dd

2 files changed

Lines changed: 27 additions & 5 deletions

File tree

README.md

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,20 +61,42 @@ return [
6161
```
6262
### Data Purning
6363
You can delete your data from your database automatically.
64+
65+
If you are using Laravel 11+ then you may use `model:prune` command.
6466
Add this to your `routes/console.php`
6567

6668
```php
6769
use Illuminate\Support\Facades\Schedule;
6870

69-
Schedule::command('model:prune')->everyMinute();
70-
```
71-
Or If you are using Laravel 11+ then you may use this also into your `bootstarp/app.php`
71+
Schedule::command('model:prune')->daily();
72+
```
73+
Or try this `bootstarp/app.php`
7274
```php
7375
use Illuminate\Console\Scheduling\Schedule;
7476
->withSchedule(function (Schedule $schedule) {
75-
$schedule->command('model:prune')->everyMinute();
77+
$schedule->command('model:prune')->daily();
7678
})
7779
```
80+
81+
If you are using Laravel 10 or below then you may use `model:prune` command.
82+
You may define all of your scheduled tasks in the schedule method of your application's `App\Console\Kernel` class
83+
```php
84+
<?php
85+
86+
namespace App\Console;
87+
88+
use Illuminate\Console\Scheduling\Schedule;
89+
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
90+
91+
class Kernel extends ConsoleKernel
92+
{
93+
protected function schedule(Schedule $schedule): void
94+
{
95+
$schedule->command('model:prune')->daily();
96+
}
97+
}
98+
```
99+
78100
You can publish the assets with this command:
79101
```bash
80102
php artisan vendor:publish --tag="request-analytics-assets"

src/Models/RequestAnalytics.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class RequestAnalytics extends Model
2424
public function prunable(): Builder
2525
{
2626
if (! config('request-analytics.pruning.enabled', false)) {
27-
return static::query();
27+
return $this->whereRaw('1 = 0');
2828
}
2929

3030
$days = config('request-analytics.pruning.days', 90);

0 commit comments

Comments
 (0)