@php use Illuminate\Support\Facades\Schema; $notificationUser = auth('admin')->user() ?? auth()->user(); // Custom app notifications use user_id on this table; do not require notifiable_* so older DBs still load. $hasNotificationColumns = Schema::hasTable('notifications') && Schema::hasColumn('notifications', 'user_id'); $useAppNotifications = $notificationUser instanceof \App\Models\User && $hasNotificationColumns; if ($useAppNotifications) { app(\App\Services\NotificationService::class)->reconcileConnectionRequestNotificationsForUser($notificationUser); } $notificationCount = $useAppNotifications ? $notificationUser->unreadNotifications()->count() : 0; $recentNotifications = $useAppNotifications ? $notificationUser->notifications()->with('sender')->latest()->limit(5)->get() : collect(); // Helper to resolve the direct target URL for each notification $resolveUrl = function($notification) { // Connection requests → requests inbox (optional fragment when we stored the row id) if (in_array((string) $notification->type, ['connection_request', 'new_connection_request'], true)) { $url = route('user.connections.requests', ['view' => 'requests', 'requests' => 1]); $cid = $notification->data['connection_id'] ?? null; if ($cid) { $url .= '#connection-request-' . (int) $cid; } return $url; } if ((string) $notification->type === 'connection_accepted') { return route('user.connect.index'); } // Connect engagement (like/comment/repost/dislike) — not connection request/accept rows $isConnectEngagement = ! in_array((string) $notification->type, ['connection_request', 'new_connection_request', 'connection_accepted'], true) && ( in_array($notification->type, ['connect_engagement', 'like', 'comment', 'repost', 'dislike'], true) || (($notification->data['category'] ?? null) === 'connect') ); if ($isConnectEngagement) { $postId = $notification->data['meta']['post_id'] ?? $notification->data['post_id'] ?? null; if ($postId) { $action = $notification->data['meta']['type'] ?? $notification->data['type'] ?? $notification->type; $query = http_build_query(array_filter(['highlight' => $postId, 'action' => $action])); return route('user.connect.index') . '?' . $query . '#post-' . $postId; } return route('user.connect.index'); } // Fallback to action_url or data.url if (!empty($notification->action_url)) { return $notification->action_url; } if (!empty($notification->data['url'])) { return $notification->data['url']; } return route('notifications.show', $notification); }; @endphp @push('scripts') @endpush