This is the structure of my table [1]: https://i.stack.imgur.com/lmgtJ.png
Users Table
id | name |
---|---|
1 | abid |
Messages Table
id | user_id | to_user | content | read |
---|---|---|---|---|
1 | 2 | 1 | message | 0 |
I want to show notifications for users like User1 send you messages (24) here 24 is the total unread messages of user1.
Problem: Notification must be shown in this order. The user that sends messages recently will show first. It is exactly the problem that I have to face.
Output Example: like the android app WhatsApp show a message in the chat area.
Note: read column type Boolean also added in the messages table.
Note: In this application only users and admin will chat with each other.
Looking for elegant Laravel 8 queries that give me results.
This should count how many messages that user sent to another user(s).
Demo: SQL Fiddle