45 lines
919 B
PHP
45 lines
919 B
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use Illuminate\Console\Command;
|
|
use Carbon\Carbon;
|
|
use App\Models\NotificationUser;
|
|
|
|
class DeleteNotification extends Command
|
|
{
|
|
/**
|
|
* The name and signature of the console command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'delete:old-notification';
|
|
|
|
/**
|
|
* The console command description.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = 'Delete data that was created 3 days ago';
|
|
|
|
/**
|
|
* Execute the console command.
|
|
*
|
|
* @return int
|
|
*/
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
public function handle()
|
|
{
|
|
// return Command::SUCCESS;
|
|
$threeDaysAgo = Carbon::now()->subDays(3);
|
|
NotificationUser::where('created_at','<',$threeDaysAgo)->delete();
|
|
|
|
$this->info('Old notifications deleted successfully.');
|
|
}
|
|
}
|