I'm trying to set up a scheduling task that can run every five minutes, but it only works 1 time, after the first five minutes, the other five minutes dont do the function correctly.
//depresiasicounter.php
protected $signature = 'updates:depresiasicounter';
public function handle()
{
$aktivatb = Aktivatb::where('id','1')->first();
$aktivatb->nilai= $aktivatb->nilai-$aktivatb->depresiasi;
$aktivatb->total_depresiasi = $aktivatb->total_depresiasi+$aktivatb->depresiasi;
$aktivatb->save();
}
//kernel.php
protected $commands = [
Commands\DepresiasiCounter::class,
];
protected function schedule(Schedule $schedule)
{
$schedule->commands('updates:depresiasicounter')->everyFiveMinutes();
}
I expect it can be work until the value of $aktivatb->nilai to 0, but it only works 1 time
You need to setup cron so it could run the php artisan schedule:run command every minute, so you need to add the following Cron entry to your server.
* * * * * php /path/to/artisan schedule:run >> /dev/null 2>&1
This Cron will call the Laravel command scheduler every minute. Then, Laravel evaluates your scheduled tasks and runs the tasks that are due.
When using the scheduler, you only need to add the following Cron entry to your server.