Anons79 Mini Shell

Directory : /home/aplikasiposinfo/www/e-tepian.aplikasipos.info/app/Console/Commands/
Upload File :
Current File : /home/aplikasiposinfo/www/e-tepian.aplikasipos.info/app/Console/Commands/DeleteOldUserLogs.php

<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Carbon\Carbon;

class DeleteOldUserLogs extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'userlogs:clean';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Hapus log pengguna yang berusia lebih dari 3 hari';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        $limitDate = Carbon::now()->subDays(3);
        $connections = ['mysql', '2024', '2025'];

        foreach ($connections as $conn) {
            $deleted = DB::connection($conn)
                ->table('user_logs')
                ->where('created_at', '<', $limitDate)
                ->delete();

            $this->info("[$conn] Sukses menghapus $deleted log yang lebih dari 3 hari.");
        }
    }
}

Anons79 File Manager Version 1.0, Coded By Anons79
Email: [email protected]