A
A
Alexander2016-03-18 13:46:39
Laravel
Alexander, 2016-03-18 13:46:39

Why does `Task Scheduling` only fire once?

app\Console\Kernel.php :

<?php
namespace App\Console;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel
{
    protected $commands = [
        \App\Console\Commands\Inspire::class,
        \App\Console\Commands\RemoveUser::class,
    ];
    protected function schedule(Schedule $schedule)
    {
        $schedule->command('inspire')
            ->hourly();
        $schedule->command('remove:user')
            ->everyMinute();
    }
}

app\Console\Commands\RemoveUser.php :
<?php
namespace App\Console\Commands;
use App\Models\User;
use Illuminate\Console\Command;
class RemoveUser extends Command
{
    protected $signature = 'remove:user';
    protected $description = 'Command description';
    public function __construct()
    {
        parent::__construct();
    }
    public function handle()
    {
        User::where('ban', 1)->delete();
    }
}

Next, I run a command in the console php artisan schedule:run >> /dev/null 2>&1
. And after that, the user whose ban field has the value 1 is deleted. Then I register a new user and give him a ban through the admin panel. I'm waiting for two minutes, but the data in the database was not deleted for some reason, although it should be `everyMinute`.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Perin, 2016-03-18
@kentuck1213

Dock . Add to cron

* * * * * php /path/to/artisan schedule:run >> /dev/null 2>&1

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question