2017-10-06 56 views
1

我正在进行任务调度,以便在特定日期或时间向用户发送短信通知。是否有可能将数据从控制器传递到内核计划?比方说:是否可以将数据从控制器传递到内核计划?

protected function schedule(Schedule $schedule) 
{ 
    $schedule->command('sms:send')->dailyAt($time); 
} 

如果可能的话,有关如何做的提示?非常感谢你。

+0

我认为你必须创建你自己的命令,并且在handel方法中你可以得到你想要的数据==> [阅读更多](https://laravel.com/docs/5.5/artisan#writing-commands) – Maraboc

+1

对不起对于迟到的回应。谢谢Maraboc。 –

回答

0

你可以叫控制器控制台/命令/ Yourclass

像这样的手柄()函数 -

protected $signature = 'showing:rating'; //your command 

//you can write and call logic here in handle function 
public function handle() 
{ 
    $rating = (new CronController())->showingRating(); 
} 

然后你就可以在内核@时间表打电话给你的命令()函数这样的 -

protected function schedule(Schedule $schedule) 
{ 
    $schedule->command('showing:rating') 
      ->hourly(); 
} 

希望这会对你有帮助。

+0

对不起,迟到的回应。我不太明白'$ rating =(new CronController()) - > shownRating();'特别是showsRating()。无论如何,谢谢你的时间。 –

+0

CronController是我的控制器,而showsRating()是一个在CronController中定义的函数。在这里,我调用了CronController中的showsRating()函数。 $ rating =(new CronController()) - > shownRating(); –

+0

我明白了。我现在明白了。非常感谢你。 –

相关问题