Initial commit: Struktur aplikasi ilycats
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use App\Models\ActivityLog;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class CleanActivityLogs extends Command
|
||||
{
|
||||
// Nama perintah yang akan dipanggil di terminal
|
||||
protected $signature = 'activity-log:clean';
|
||||
|
||||
// Deskripsi perintah
|
||||
protected $description = 'Menghapus log aktivitas yang sudah lebih dari 30 hari';
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$days = 30;
|
||||
$date = Carbon::now()->subDays($days);
|
||||
|
||||
// Menghitung jumlah log yang akan dihapus untuk laporan di terminal
|
||||
$count = ActivityLog::where('created_at', '<', $date)->count();
|
||||
|
||||
if ($count > 0) {
|
||||
ActivityLog::where('created_at', '<', $date)->delete();
|
||||
$this->info("Berhasil menghapus {$count} log lama.");
|
||||
} else {
|
||||
$this->info("Tidak ada log lama yang perlu dihapus.");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user