EVOLUTION-NINJA
Edit File: Dashboard.php
<?php namespace App\Controllers; class Dashboard extends BaseController{ public function __construct() { $this->db = \Config\Database::connect(); } public function index() { $promoter_id = session()->get('id'); $builder = $this->db->table('notifications'); $notifications = $builder->select('*') ->where('send_to', $promoter_id) ->where('status', 'unread') ->get() ->getResultArray(); // Count unread notifications $unreadCount = count($notifications); return $this->response->setJSON([ 'notifications' => $notifications, 'unreadCount' => $unreadCount ]); } public function markAsRead() { $promoter_id = session()->get('id'); $this->db->table('notifications') ->where('send_to', $promoter_id) ->where('status', 'unread') ->update(['status' => 'read']); return $this->response->setJSON([ 'result' => 1, 'message' => 'Users and message are required.' ]); } public function send_notification() { $promoter = $this->request->getPost('users'); $message = $this->request->getPost('message'); if (empty($promoter) || empty($message)) { return $this->response->setJSON([ 'result' => 0, 'message' => 'Users and message are required.' ]); } if (!is_array($promoter)) { $promoter = explode(',', $promoter); } $data = []; foreach ($promoter as $user) { $data[] = [ 'send_to' => trim($user), 'message' => $message, ]; } $builder = $this->db->table('notifications'); if ($builder->insertBatch($data)) { return $this->response->setJSON([ 'result' => 1, 'message' => 'Message sent successfully .' ]); } else { return $this->response->setJSON([ 'result' => 0, 'message' => 'Failed to send message.' ]); } } }?>