默认地Laravel的计划任务文件都是写在了app/Console/Kernel.php中, 如果需要自定义在其他的地方, 那么你可以自定义个服务提供者
ScheduleServiceProvider
扩展配置文件
创建Schedule服务提供者
php artisan make:provider ScheduleServiceProvider
简单测试
<?php
namespace App\Providers;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Support\ServiceProvider;
class ScheduleServiceProvider extends ServiceProvider
{
/**
* Bootstrap the application services.
*
* @return void
*/
public function boot()
{
$this->app->booted(function(){
$schedule = $this->app->make(Schedule::class);
$schedule->command('list:order')->everyMinute();
});
}
...
优化, 直接加载文件
$this->app->booted(function(){
$schedule = $this->app->make(Schedule::class);
include_once app_path('Console/Schedule.php');
});
测试, 手动运行计划任务
php artisan schedule:run