Azoruk
1 week ago

Check for unread messages in service provider OR ajax request?

Posted 1 week ago by Azoruk

Imagine you have a private message system. You want to run code that regularly checks if the current auth user has any new message with unread set to true.

Where are you putting this code?

Maybe adding a check in AppServiceProvider when loading partial view with your navbar (editing boot method) and just return all messages that are new to that partial view?

Or maybe that's too many queries.

Maybe make it an ajax request that runs on every page load, but add a cookie that makes it so that the ajax request only runs if it hasn't been run in over 2 minutes.

Thoughts?

Please sign in or create an account to participate in this conversation.