我尝试使用Laravel Scheduler在EveryMinute上运行控制器功能,但不起作用
这是我的app\console\kernel.php
<?php
namespace App\Console;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel
{
/**
* The Artisan commands provided by your application.
*
* @var array
*/
protected $commands = [
//
];
/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
// $schedule->command('inspire')
// ->hourly();
$obj = new HomeController();
$schedule->call(function () use ($obj) {
$obj->daily_set_profit(); //call method
})->everyMinute();
}
/**
* Register the commands for the application.
*
* @return void
*/
protected function commands()
{
$this->load(__DIR__.'/Commands');
require base_path('routes/console.php');
}
}
答案 0 :(得分:0)
不要忘记运行
php artisan schedule:run
最后,您可以在调度任务上管理此命令,您必须在服务器的crontab文件中添加一个条目
* * * * * php /path/to/artisan schedule:run 1>> /dev/null 2>&1
或
* * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1
遵循此tutorial,简单又非常有用