tvbz's avatar
Level 4

How to add a relation to Laravel Notifications?

I'm using the Laravel Notifications in a experimental project. But I'm struggling with how to use notifications inside the legal scope of EU privacy law. The fact that all notification data is saved in the data column makes it a bit harder to manage. Personal data like username, profile image, etc. would probably get stored in this data column.

To work around this issue, I would only need to add a user relation to the model. Something like caused_by. This way I can avoid storing personal data in the notifications table, but instead just store a user ID and get the relation.

Notifications are just stuff like, "X commented on your post". X would be the relation. By using nullOnDelete(), personal data can be removed when caused_by user is removed, without actually losing the notification. Also, when the caused_by changes username/avatar, there would be no traces of old username/avatar in notifications table. It just make more sense to me.

Is it possible to extend the notifications and add a relation to it? If so, how would you do it?

0 likes
0 replies

Please or to participate in this conversation.