check the timezone of your server
Schedule command not working
I created a new command named: DeleteOfferCommand and it looks like this:
class DeleteOfferCommand extends Command
{
protected $signature = 'app:delete-offer';
protected $description = 'Delete expired offers';
public function handle()
{
$offers = Offer::all();
foreach($offers as $offer){
if(now() >= $offer->expires_at){
$offer->delete();
}
}
}
}
In the tutorial, I see that there is a folder called start which I should use to intiate the command:
Artisan::add(new DeleteOfferCommand);
However, I do not see that folder on my side, also checked laravel documentation and didnt see that instruction.
Moving on, I went to my forge account and created a new schedule which looks like the following:
php /home/forge/mysite.com/artisan app:delete-offer
If I ssh into the server and run the artisan command, I am able to see the command.
app:delete-offer Delete expired offers
But when I go to my site, I do not see any effect.
The offer expired about an hour ago but It wasnt delete.
Anything I need to add to make my code work?
The offer expired about an hour ago but It wasnt delete.
In case needed, this is how I save the offer in my controller:
public function store(Request $request)
{
$this->validate($request, [
'offer_price' => 'required',
'offer_period' => 'required',
'offer_message' => 'required',
]);
$expires_at = now()->addMinutes($request->offer_period);
$this->validate($request, [
'cash_amount' => 'required',
]);
$offer = Offer::Create([
'user_id' => Auth::id(),
'property_id' => 2,
'offer_price' => $request->offer_price,
'offer_period' => $request->offer_period,
'offer_message' => $request->offer_message,
'cash_amount' => $request->cash_amount,
'buyer_type' => $request->buyer_type,
'expires_at' => $expires_at,
]);
}
Anything I need to add to make my code work?
Please or to participate in this conversation.