关闭
doutan2456 2015-10-01 02: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 03: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).

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

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部