I've been on this for a few hours without solution. I thought of laravel relationships but don't know how to pass a second condition because I need to relate with 3 tables. I'd like to use the query below in laravel.
SELECT
subscriptions.subscribed_to,
broadcasts. *,
FROM subscriptions
INNER JOIN broadcasts
WHERE subscriptions.subscriber = {$user_id}
AND (
SELECT COUNT(*) FROM seen_broadcasts
WHERE user_id = {$user_id}
AND broadcast_id = broadcasts.id
) = 0
ORDER BY broadcast.date DESC
There are 3 tables.
- subscriptions: subscriber_id subscribes to broadcaster_id.
- broadcasts: where broadcaster's message is saved.
- seen_broadcast: where the information of subscribers are saved when they read a broadcast. This helps us provide detailed stats to broadcaster.
user_id = subscriber_user_id, broadcast_id = broadcast_message_id
I want to be able to get broadcasts from all broadcaster that userA has subscribed to and have not seen.
The query above currently works outside laravel.
user_id = subscriber_user_id, broadcast_id = broadcast_message_idI want to be able to get broadcasts from all broadcaster that userA has subscribed to and have not seen. I hope this is clear enough