laravel中的Cron(使用https://github.com/liebig/cron)


Cron in laravel (using https://github.com/liebig/cron)

好的,我已经安装了https://github.com/liebig/cron这一切都在起作用…

不过,我在实现这一点时遇到了麻烦。在我的laravel/app/start/global.php 中

我放这个:

Event::listen('cron.collectJobs', function() {
    Cron::add('deposit_reminder', '* * * * *', function() {
        foreach (Site::where('org_id', Auth::user()->organization->id)->get() as $site){    
            foreach (Game::get() as $game) {    
        ALOT MORE CORE IS HERE thats not really relevant to see
        Cron::setEnableJob('deposit_reminder');
        return null;
    });
});

有了global.php中的这段代码,我想我正在尝试使用Auth::user()->etc.。然而,在这一点上,登录还不会被触发,因为我想这是在laravel启动时?

我曾尝试将此代码放入routes.php中,成功登录后,会创建此cron作业,但当我这样做时,似乎不会为cronjob创建作业。。。有人有什么建议吗?

我想好了该怎么做,而不是使用Auth::user,只需要在用户模型上循环,所以做一个user::get(),然后可以使用它在每个用户中循环,并根据数据库中的标准发送电子邮件。

工作完美,我希望这能在未来帮助其他人。