dongtang4954 2019-07-31 09:27
浏览 229

Laravel在文章发布时发送通知

I have a Laravel app where users can subscribe to a blog tags and they need to receive notifications when an article is added to the tags they subscribed to. But we have specific needs that make it more complex :

  • An article can have many tags (added anytime)
  • An article can have a publishing date in the future
  • An article can have a draft state and so it's not yet visible for the visitors

So if an admin create an article in draft mode, we shouldn't send notification until it remove it from draft mode and the publication date has arrived.

My problem is that because I don't know when the admin will remove the draft mode I can't create queued notification with a delay. Also because he can add a tag anytime I can't just send all the notifications when the draft mode is removed because he can come back later and add an other tag...

The only option that I have in mind is to save in a pivot table any changes that happend before it was published and when it's published send all notifications. But it feels a little weird.

I hope some of you had this kind of multi-state model that need to release some notifications, or do some actions, when it's visible to the users...

  • 写回答

1条回答 默认 最新

  • doubengshao8872 2019-07-31 09:47
    关注

    I think model events should be a good solution for you :

    https://laravel.com/docs/5.8/eloquent#events

    It gives you the opportunity to run some logic before (or after) creating/updating/deleting a model. So every time a post/tag/post_tag is updated (or created), you will be able to check if it became published or if it got a new tag.

    Let me know if it helped !

    评论

报告相同问题?

悬赏问题

  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失