search

Home  >  Q&A  >  body text

Laravel crontab task new question

  1. 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:

  1. You can copy artisan files to app/crontab (new directory). Rename it as a new script.

  2. 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.

大家讲道理大家讲道理2750 days ago457

reply all(1)I'll reply

  • 巴扎黑

    巴扎黑2017-05-16 16:53:05

    Use the call aspect directly and put your logic into the anonymous function
    $schedule->call(function () {

            DB::table('recent_users')->delete();
        })->daily();

    reply
    0
  • Cancelreply