简体   繁体   English

下次用户在Laravel 5.4应用程序中登录时通知用户

[英]Notify user when next time user login in Laravel 5.4 Application

I am looking for a solution to notify all the users for occurrence of X activity in the app. 我正在寻找一种解决方案,以通知所有用户应用程序中X活动的发生。

I am not looking for notification by mail or sms. 我不希望通过邮件或短信通知。 Because this specific notification would be send to all the users, which could be anywhere between 1000 to 25000 users. 因为此特定通知将发送给所有用户,所以可能在1000到25000个用户之间。 sending 1000s of mail or sms is waste of resources. 发送数千封邮件或短信会浪费资源。

I want to notify users using something which goes noticed, that is they would read. 我想使用会引起注意的东西通知用户,即他们会阅读。 for example: if the X activity has happened today. 例如:如果X活动今天已经发生。 And Y user logins after 10 days he/she must be able to see the notification (I guess flash message wont work in this case). 并且Y用户在10天后登录,他/她必须能够看到通知(我想在这种情况下Flash消息不起作用)。

What is the best and most efficient way possible? 最好和最有效的方法是什么? if notification using database is the way that I think. 如果使用数据库通知是我的想法。 How can I create a single notification (single entry in database) and make sure all the users read that notification next time login? 如何创建一个通知(数据库中的单个条目),并确保所有用户下次登录时都阅读该通知? without creating 1000s of rows? 没有创建数千行?

I think storing notifications in the database would be the way to go too. 我认为将通知存储在数据库中也是一种方法。

If you add a many-to-many relationship between your User and Notification models, with a is_read flag on the relationship pivot table. 如果在User模型和Notification模型之间添加多对多关系,则在关系数据透视表上带有is_read标志。

Then when a user reads the notification, you update the is_read flag to 1 . 然后,当用户阅读通知时,将is_read标志更新为1 Alternatively, if you don't need to keep the notification for that user, you could delete the relationship, thus reducing storage of obsolete records. 或者,如果您不需要保留该用户的通知,则可以删除该关系,从而减少过时记录的存储。

Edit 编辑

If every user will always see every notification, then you could store the last_login_at timestamp on your User model, which is updated each time a user logs in. 如果每个用户总是看到每个通知,则可以将last_login_at时间戳存储在User模型中,该时间戳在User每次登录时都会更新。

Then each time a user logs in, find all Notification s created since the last_login_at and show them to the user. 然后,每次用户登录时,查找自last_login_at以来创建的所有Notification ,并将其显示给用户。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM