Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Antonella's avatar

timed query that takes place every morning at 08

Hello I have this table:

 Polls(id,name,...ecc);

I would like to run a query every morning at 08 that does some operations on it. Like deleting some content.

give example:

$trash= App\Models\Poll::where('name','=','running')->delete();

possible to create a cron tab on laravel? if yes how should i implement it given such a query?

0 likes
3 replies
tykus's avatar

Create a scheduled command which executes your query; the scheduler api is very intuitive. You will need to run a single cron task to run the scheduler.

If the task is as simple as you are showing above, then a Closure command would be enough:

// app/Console/Kernel.php

protected function schedule(Schedule $schedule)
{
        $schedule->call(function () {
            $trash= App\Models\Poll::where('name','=','running')->delete();
        })->dailyAt('08:00');
}
tykus's avatar

@gianmarx if you look into the app/Console/Kernel.php file, you will see that the method is already present with the Laravel installation, and is protected, and is called by the parent ConsoleKernel class, hence protected and not private.

Please or to participate in this conversation.