Files
hub/app/Http/Controllers/NotificationController.php
kelly 3905f86d6a feat: V1 Release - Complete platform with all premium modules
Major Features:
- CRM Lite: Pipeline, tasks, accounts, calendar, inbox
- AI Copilot: Multi-provider support, brand voice, content rules
- Marketing: Campaigns, templates, channels, broadcasts
- Intelligence: Buyer analytics, market intelligence dashboard
- Orchestrator: Sales & marketing automation with AI
- Compliance: License tracking (minimal shell)
- Conversations: Buyer-seller messaging with email/SMS routing

Infrastructure:
- Suites & Plans system for feature gating
- 60+ new migrations
- Module middleware for access control
- Database seeders for production sync
- Enhanced product management (varieties, inventory modes)

Documentation:
- V1 scope, launch checklist, QA scripts
- Module current state audit
- Feature matrix (standard vs premium)
2025-12-01 09:48:40 -07:00

165 lines
4.8 KiB
PHP

<?php
namespace App\Http\Controllers;
use App\Models\Notification;
use App\Services\NotificationService;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class NotificationController extends Controller
{
public function __construct(
protected NotificationService $notificationService
) {}
/**
* Display the notifications center page for sellers.
*/
public function index()
{
$user = Auth::user();
$business = $user->primaryBusiness();
if (! $business) {
return redirect()->route('seller.dashboard')
->with('error', 'Please complete your business profile first.');
}
$query = Notification::forBusiness($business->id)
->where(function ($q) use ($user) {
$q->whereNull('user_id')
->orWhere('user_id', $user->id);
})
->latest();
$notifications = $query->paginate(20);
$unreadCount = $this->notificationService->getUnreadCountForBusiness($business, $user);
return view('seller.notifications.index', compact('notifications', 'unreadCount', 'business'));
}
/**
* Get notifications for dropdown (API endpoint).
*/
public function dropdown()
{
$user = Auth::user();
$business = $user->primaryBusiness();
if (! $business) {
return response()->json([
'notifications' => [],
'unread_count' => 0,
'has_more' => false,
]);
}
$notifications = $this->notificationService->getRecentForBusiness($business, $user, 10);
$unreadCount = $this->notificationService->getUnreadCountForBusiness($business, $user);
return response()->json([
'notifications' => $notifications->map(function ($notification) {
return [
'id' => $notification->id,
'type' => $notification->type,
'title' => $notification->title,
'message' => $notification->message,
'icon' => $notification->icon,
'color' => $notification->color,
'action_url' => $notification->action_url,
'created_at' => $notification->created_at->diffForHumans(),
'read_at' => $notification->read_at,
'is_unread' => $notification->isUnread(),
];
}),
'unread_count' => $unreadCount,
'has_more' => Notification::forBusiness($business->id)->count() > 10,
]);
}
/**
* Mark a notification as read.
*/
public function markAsRead(Request $request, $id)
{
$user = Auth::user();
$business = $user->primaryBusiness();
$notification = Notification::forBusiness($business->id)
->where(function ($q) use ($user) {
$q->whereNull('user_id')
->orWhere('user_id', $user->id);
})
->findOrFail($id);
$notification->markAsRead();
if ($request->expectsJson()) {
return response()->json(['success' => true]);
}
return back();
}
/**
* Mark a notification as unread.
*/
public function markAsUnread(Request $request, $id)
{
$user = Auth::user();
$business = $user->primaryBusiness();
$notification = Notification::forBusiness($business->id)
->where(function ($q) use ($user) {
$q->whereNull('user_id')
->orWhere('user_id', $user->id);
})
->findOrFail($id);
$notification->markAsUnread();
if ($request->expectsJson()) {
return response()->json(['success' => true]);
}
return back()->with('success', 'Notification marked as unread.');
}
/**
* Mark all notifications as read.
*/
public function readAll(Request $request)
{
$user = Auth::user();
$business = $user->primaryBusiness();
if ($business) {
$this->notificationService->markAllAsReadForBusiness($business, $user);
}
if ($request->expectsJson()) {
return response()->json(['success' => true]);
}
return back()->with('success', 'All notifications marked as read.');
}
/**
* Get unread notification count (for real-time updates).
*/
public function unreadCount()
{
$user = Auth::user();
$business = $user->primaryBusiness();
$count = $business
? $this->notificationService->getUnreadCountForBusiness($business, $user)
: 0;
return response()->json([
'unread_count' => $count,
]);
}
}