简体   繁体   中英

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.

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. 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. 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).

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.

Then when a user reads the notification, you update the is_read flag to 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.

Then each time a user logs in, find all Notification s created since the last_login_at and show them to the user.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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