Files
mtdb_movie/common/Auth/Commands/DeleteExpiredBansCommand.php
maher 703f50a09d
Some checks failed
Build / run (push) Has been cancelled
first commit
2025-10-29 11:42:25 +01:00

30 lines
710 B
PHP
Executable File

<?php
namespace Common\Auth\Commands;
use Common\Auth\Ban;
use Illuminate\Console\Command;
use Illuminate\Support\Carbon;
class DeleteExpiredBansCommand extends Command
{
protected $signature = 'bans:deleteExpired';
protected $description = 'Unban users whose ban date has expired.';
public function handle(): int
{
$bans = Ban::query()
->where('expired_at', '<=', Carbon::now()->format('Y-m-d H:i:s'))
->get();
$bans->each(function ($ban) {
$ban->created_by->fill(['banned_at' => null])->save();
$ban->delete();
});
$this->info("Unbanned {$bans->count()} users.");
return Command::SUCCESS;
}
}