Implement cron to remove expired bids
This commit is contained in:
30
app/Cron/Hourly/RemoveExpiredBids.php
Normal file
30
app/Cron/Hourly/RemoveExpiredBids.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Cron\Hourly;
|
||||
|
||||
use App\Events\CronHourly;
|
||||
use App\Interfaces\Listener;
|
||||
use App\Models\Bid;
|
||||
use Carbon\Carbon;
|
||||
|
||||
/**
|
||||
* Remove expired bids
|
||||
* @package App\Listeners\Cron\Hourly
|
||||
*/
|
||||
class RemoveExpiredBids extends Listener
|
||||
{
|
||||
/**
|
||||
* Remove expired bids
|
||||
* @param CronHourly $event
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function handle(CronHourly $event): void
|
||||
{
|
||||
if(setting('bids.expire_time') === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
$date = Carbon::now()->subHours(setting('bids.expire_time'));
|
||||
Bid::whereDate('created_at', '<', $date)->delete();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user