doutan2456 2015-10-01 10:54
浏览 25
已采纳

在cron作业中使用toastr

I'm using laravel toastr feature (link here). I just want to ask if it's possible or is there any way to have the toastr functionality inside a cron job then throw the toastr result in the web page?

Also I dont want to use any web socket. I'm just asking if anyone has a suggestion.

Thanks

  • 写回答

1条回答 默认 最新

  • douningle7944 2015-10-01 11:23
    关注

    OK if I understand correctly what you want to do is an async message to the user one way to do it is use WebSocket and add a JavaScript that listens to that and if there is any incoming data show the toastr. Problem is you don't want WebSockets. The other option is hsow the toastr message once the user load the page but this won't be exactly what you want as that will require page reload to get the data from the server though I guess that's as close as you can get. You can have following code in the main template file:

    @if (Session::has('flash_notification.message'))
    
        <script>
            $(document).ready(function() {
    
            toastr.{{ Session::get('flash_notification.level') }}
            ('{{ Session::get('flash_notification.message') }}');
    
            });
        </script>
    
    @endif
    

    and you need another script or Laravel command that gets executed regularly from the CRONJOB and that should write to DB or file. Once the data has been written you can read it in the Contrller or the Model and append it in the Session, you can use a timestamp so you don't print duplicate toastrs.

    Alternativelly you can have a JavaScript in the page that will poll an endpoint every-now-and-then and if there's been update it will show the notification but that will add extra load to your webserver (Apache).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度