【问题标题】:Cron in laravel (using https://github.com/liebig/cron)laravel 中的 Cron(使用 https://github.com/liebig/cron)
【发布时间】:2015-04-08 02:34:57
【问题描述】:

好的,我已经安装了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()-> 等...但是此时登录不会被触发,因为这是在我认为 Laravel 启动了吗?

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

【问题讨论】:

    标签: php laravel cron


    【解决方案1】:

    我想出了要做什么而不是使用 Auth::user,只需要循环遍历用户模型,所以使用 User::get() 并且可以使用它来遍历每个用户并发送电子邮件基于数据库中的标准。

    完美无瑕,我希望这对将来的其他人有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-11-30
      • 1970-01-01
      • 2021-09-21
      • 2021-12-17
      • 2013-10-09
      • 2021-03-21
      • 2015-05-27
      • 2018-03-11
      相关资源
      最近更新 更多