1 | <?php |
||
9 | class CleanActivitylogCommand extends Command |
||
10 | { |
||
11 | /** |
||
12 | * The console command name. |
||
13 | * |
||
14 | * @var string |
||
15 | */ |
||
16 | protected $signature = 'activitylog:clean'; |
||
17 | |||
18 | /** |
||
19 | * The console command description. |
||
20 | * |
||
21 | * @var string |
||
22 | */ |
||
23 | protected $description = 'Clean up old records from the activity log.'; |
||
24 | |||
25 | public function handle() |
||
26 | { |
||
27 | $this->comment('Cleaning activity log...'); |
||
28 | |||
29 | $maxAgeInDays = config('laravel-activitylog.delete_records_older_than_days'); |
||
30 | |||
31 | $cutOffDate = Carbon::now()->subDays($maxAgeInDays)->format('Y-m-d H:i:s'); |
||
32 | |||
33 | $amountDeleted = Activity::where('created_at', '<', $cutOffDate)->delete(); |
||
34 | |||
35 | $this->info("Deleted {$amountDeleted} record(s) from the activity log."); |
||
36 | |||
37 | $this->comment('All done!'); |
||
38 | } |
||
40 |