Tutorial: Hooking Comments Notification Callback Triggers

Hooking Comments Notification Callback Triggers

Hooking Comments Notification Callback Triggers php
namespace App\Modules\Blog\Controllers\Api;

class CustomCommentsHandler 
{
    public static function notifySubscribers(array $comment, array $post)
    {
        // Retrieve comment notifiers array dynamically from post column
        $notifierIds = json_decode($post['comment_notifiers'] ?? '[]', true);
        if (!empty($notifierIds)) {
            $placeholders = implode(',', array_fill(0, count($notifierIds), '?'));
            $users = DB::query("SELECT email FROM users WHERE id IN($placeholders) AND deleted_at IS NULL", $notifierIds)->fetchAll();
            
            foreach ($users as $u) {
                Emailer::send($u['email'], "New comment alert: " . $post['title'], "Author: " . $comment['author_name']);
            }
        }
    }
}