40 lines
909 B
PHP
40 lines
909 B
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Models\Notifications;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Console\Command;
|
|
|
|
//phpcs:disable Generic.Files.LineLength.TooLong
|
|
class PurgeNotifications extends Command
|
|
{
|
|
|
|
/**
|
|
* The name and signature of the console command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'notifications:purge';
|
|
|
|
/**
|
|
* The console command description.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = 'Purge the notifications table where the created_at date of a notification is older than 30 days';
|
|
|
|
/**
|
|
* Execute the console command.
|
|
*
|
|
* @return int
|
|
*/
|
|
public function handle()
|
|
{
|
|
$this->info("Start purging notifications table...");
|
|
|
|
Notifications::where('created_at', '<', Carbon::now()->subDays(30))->delete();
|
|
|
|
$this->info("Notifications table successfully purged!");
|
|
}
|
|
}
|