latest() ->paginate(10); $users = User::select('id', 'first_name', 'last_name', 'email') ->where('status', 'active') ->get(); return Inertia::render('Notifications/Index', [ 'logs' => [ 'data' => $logs->items(), 'meta' => [ 'current_page' => $logs->currentPage(), 'last_page' => $logs->lastPage(), 'total' => $logs->total(), 'per_page' => $logs->perPage(), ], 'links' => $logs->linkCollection()->toArray(), ], 'users' => $users, ]); } public function store(Request $request) { $validated = $request->validate([ 'title' => 'required|string|max:255', 'body' => 'required|string', 'image_url' => 'nullable|url', 'deep_link' => 'nullable|string', 'target_type' => 'required|in:all,individual', 'target_user_id' => 'required_if:target_type,individual|nullable|exists:users,id', ]); try { // Mocking FCM Sending logic // In production, use Kreait/Firebase-PHP or Laravel-Notification-Channels/WebPush $status = 'sent'; $errorMessage = null; // Log the notification NotificationLog::create([ 'title' => $validated['title'], 'body' => $validated['body'], 'image_url' => $validated['image_url'], 'deep_link' => $validated['deep_link'], 'target_type' => $validated['target_type'], 'target_user_id' => $validated['target_user_id'], 'sender_id' => auth()->id(), 'status' => $status, 'error_message' => $errorMessage, ]); return back()->with('success', 'Notification dispatched successfully.'); } catch (\Exception $e) { Log::error('FCM Error: ' . $e->getMessage()); return back()->with('error', 'Failed to send notification: ' . $e->getMessage()); } } }