Laravel crontab task new question
大家讲道理
大家讲道理 2017-05-16 16:51:05
0
1
488
  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.

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(1)
巴扎黑

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

        DB::table('recent_users')->delete();
    })->daily();
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template