How to write crontab in laravel? The official website tutorial says to write it in the shedule function in /app/Console/Kenel.php. But this code is a lot unsightly.
Currently thinking points:
You can copy artisan files to app/crontab (new directory). Rename it as a new script.
Make modifications based on the code in artisan. . Examples are as follows:
#!/usr/bin/env php <?php require __DIR__.'/bootstrap/autoload.php'; $app = require_once __DIR__.'/bootstrap/app.php'; $kernel = $app->make(Illuminate\Contracts\Console\Kernel::class); $status = $kernel->handle( $input = new Symfony\Component\Console\Input\ArgvInput, new Symfony\Component\Console\Output\ConsoleOutput ); $kernel->terminate($input, $status); exit($status);
Among them, my idea should be to change the things in the handle into the functions I want to execute. However, after checking that the handle function parameter is a $request, I don’t understand how to implement it. Friends who know how to do this are welcome to give me some advice.
Use the call aspect directly and put your logic into the anonymous function
$schedule->call(function () {