Files
vedant-chavan/app/Console/Commands/DeleteNotification.php
vedant-chavan eff0228447 first commit
2024-06-12 20:29:05 +05:30

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.');
}
}