定时计划任务文件
在 Console/Commands 下创建计划任务文件,例如:DeleteMatchCrontab.php
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
class DeleteMatchCrontab extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'crontab:delete-match';
/**
* The console command description.
*
* @var string
*/
protected $description = '删除匹配记录';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
// 处理业务内容
}
}
注册计划任务
Kernel.php
<?php
namespace App\Console;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
use Illuminate\Support\Facades\Artisan;
class Kernel extends ConsoleKernel
{
/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
$schedule->call(function () {
Artisan::call("crontab:delete-match");
})->dailyAt('1:30');
}
/**
* Register the commands for the application.
*
* @return void
*/
protected function commands()
{
$this->load(__DIR__.'/Commands');
require base_path('routes/console.php');
}
}
更多精彩内容:各种AI课程、技能课程、黑科技软件、网站小程序源码、副业小项目、PPT模板等精品素材、电商课程、推广引流课程等,尽在 天边资源网 。