Hello, so I have an application in Laravel in which a lot of user data is stored in separate tables across several models. I now have a requirement to create an activity feed 'like Instagram activity', which means ordering the various data across tables by date.
For illustrative purposes, imagine I have 3 models, Post, Comment and Like, and of course the User. model
I want a feed that combines both by date. merge() is not an option because they may have the same id.
Therefore I could UNION them, but my problem is I won't know what came from what.
So:
My posts table:
+------------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+------------------+------+-----+---------+----------------+
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
| user_id | int(11) | NO | | NULL | |
| content | varchaer(191) | NO | | NULL | |
| created_at | timestamp | YES | | NULL | |
| updated_at | timestamp | YES | | NULL | |
+------------+------------------+------+-----+---------+----------------+
And my likes table looks like this:
+------------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+------------------+------+-----+---------+----------------+
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
| user_id | int(11) | NO | | NULL | |
| asset_id | int(11) | NO | | NULL | |
| created_at | timestamp | YES | | NULL | |
| updated_at | timestamp | YES | | NULL | |
+------------+------------------+------+-----+---------+----------------+
Finally my comments table:
+------------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+------------------+------+-----+---------+----------------+
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
| post_id | int(11) | NO | | NULL | |
| user_id | int(11) | NO | | NULL | |
| content | varchaer(191) | NO | | NULL | |
| created_at | timestamp | YES | | NULL | |
| updated_at | timestamp | YES | | NULL | |
+------------+------------------+------+-----+---------+----------------+
what I need is to get the user feed,
let's say I have 2 users
if user 1 share a post, then user 2 comment on it
user 1 will get in the activity tab:
'username.of.id.2' Commented 'this is the comment' On Your 'post.id'
Thanks in advance.