Support the ongoing development of Laravel.io →
posted 8 years ago
Architecture

Hello!

So for a single notifiable user, a single entry in the notifications table, along with a mail/sms sent is perfectly working.

An important issue I'm facing with this however, is when I have a user collection, a list of 1k users following me, and I post an update. Here is what happens when using the Notifiable trait as suggested for multi user case:

  1. 1k mails/sms sent (issue not here)
  2. 1k notification entries added to the db notifications table

It seems that adding 1k notifications to the db notifications table is not an optimal solution. Since the toArray data is the same, and everything else in the db notifications table is the same for 1k rows, with the only difference being the notifiable_id of the user notifiable_type.

An optimal solution out of the box would be:

  1. laravel would pick up the fact that it's an array notifiable_type
  2. Save a single notification as notifiable_type user_array or user with notifiable_id 0 (zero would only be used to signify it's a multi notifiable user)
  3. Create/use another table notifications_read using the notification_id it just created as the foreign_key and insert 1k rows, of just these fields: notification_id notifiable_id notifiable_type read_at

I am hoping there is already a way to do this as I am at this point in my application and would love to use the built in Notifications for this situation, as I am firing off emails/sms notifications, which is fine to repeat 1k times I think, but it's the entry of the same data into the db that is the problem that needs to be optimized.

Any thoughts/ideas how to proceed in this situation?

Last updated 3 years ago.
0

Sign in to participate in this thread!

PHPverse

Your banner here too?

Wonka wonka Joined 4 Nov 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.