Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

talhaatsix's avatar

How to design Notification Table for Social Networking Site

I need help to build notification system , im stuck with database design .

Posts Like 
Friend Request  
Follow User  
Send Message 
Comment on post 
Like Comments 
Reply Comment Post  

need suggestion

database design dont share laravel topic link

0 likes
3 replies
ravasaurio's avatar
Level 2

https://laravel.com/docs/5.8/notifications#database-notifications

Laravel uses a single table for all of your notifications. You can create this table by executing the php artisan notifications:table command and then php artisan migrate. Then you can use php artisan make:notification YourNotificationClassName to create the notifications you need (post like, friend request etc). Once you have your notifications ready, you can notify your users with $user->notify(new YourNotificationClassName()). This will create a record on the notifications table. Note that the data column on this table will hold an array you can define on the toArray method of every notification. Use this if you need to store something like a friend request text or something.

You can iterate through a user's notifications with:

foreach ($user->notifications as $notification) {
    // do your thing
}

or

foreach ($user->unreadNotifications as $notification) {
    // do your thing
}

You can count them:

$user->notifications->count();
$user->unreadNotifications->count();

And you can mark them as read or delete them.

2 likes

Please or to participate in this conversation.