Adding column to Database Notifications table
When you need additional scope on notifications
Last updated
Was this helpful?
When you need additional scope on notifications
Last updated
Was this helpful?
Suppose your user can belong to many teams, and they have the ability to switch teams, you, like me, may want to allow the user to have unread notifications only for the team that they are currently in.
A similar situation may exist for multi-tenant applications where the same user can be a member of different tenants.
You may find that you need an additional column on the notifications table that you can then later filter with a global scope.
This article: suggests creating a new database notification channel.
The approach presented here is simpler as it only involves listening to the Notification Eloquent model creating event using an .
This is fairly straightforward, just a regular migration targeting the notifications table
If you don't already have it, create app\Observers table
Create new file NotificationObserver.php
In the boot() method of Providers/AppServiceProvider
Thats it! when your database notification is created, your additional data will be added