@props(['breadcrumbs', 'simple' => false, 'showTitle' => true, 'title' => null]) @php use App\Services\BreadcrumbService; $breadcrumbService = app(BreadcrumbService::class); // If breadcrumbs not provided, generate them if (!isset($breadcrumbs)) { $breadcrumbs = $simple ? $breadcrumbService->getSimpleBreadcrumbs() : $breadcrumbService->getFullPathBreadcrumbs(); } // Get page title - automatically show for all pages $pageTitle = $title; // Auto-detect title (enabled by default unless explicitly disabled) if ($showTitle !== false) { // Get Livewire component from view (Filament pages are Livewire components) $livewire = null; if (isset($this)) { $livewire = $this; } elseif (class_exists('\Livewire\Livewire')) { try { $livewire = \Livewire\Livewire::current(); } catch (\Exception $e) { // Ignore errors } } // Also try to get from view data if available if (!$livewire && isset($__env) && method_exists($__env, 'getData')) { try { $viewData = $__env->getData(); if (isset($viewData['__livewire'])) { $livewire = $viewData['__livewire']; } } catch (\Exception $e) { // Ignore errors } } // Try to get title from the current page/component if ($pageTitle === null && $livewire) { // First try getPageTitle() - most pages have this and it returns navigationLabel if (method_exists($livewire, 'getPageTitle')) { try { $pageTitle = $livewire->getPageTitle(); } catch (\Exception $e) { // Ignore errors } } // Then try getTitle() if (empty($pageTitle) && method_exists($livewire, 'getTitle')) { try { $pageTitle = $livewire->getTitle(); } catch (\Exception $e) { // Ignore errors } } // Then try getHeading() (but skip if empty) if (empty($pageTitle) && method_exists($livewire, 'getHeading')) { try { $heading = $livewire->getHeading(); if (!empty($heading)) { $pageTitle = $heading; } } catch (\Exception $e) { // Ignore errors } } } // For resource pages, try to get from resource directly if (empty($pageTitle) && $livewire && method_exists($livewire, 'getResource')) { try { $resource = $livewire->getResource(); if ($resource) { // For list pages, use plural model label if available if (method_exists($livewire, 'getPluralModelLabel')) { $pageTitle = $livewire->getPluralModelLabel(); } // Otherwise use navigation label (most common for resources) if (empty($pageTitle)) { $pageTitle = $resource::getNavigationLabel(); } // Fallback to model label if (empty($pageTitle) && method_exists($resource, 'getModelLabel')) { $pageTitle = $resource::getModelLabel(); } } } catch (\Exception $e) { // Ignore errors } } // Fallback: Try to get title from route/resource name if still not found if (empty($pageTitle)) { try { $route = request()->route(); if ($route) { $routeName = $route->getName(); // Pattern: filament.admin.resources.{resource}.{page} if (preg_match('/filament\.admin\.resources\.([^.]+)\.(.+)/', $routeName, $matches)) { $resourceName = $matches[1]; $page = $matches[2]; // Try to find the resource class $resourceClass = 'App\\Filament\\Resources\\' . str_replace(' ', '', ucwords(str_replace(['-', '_'], ' ', $resourceName))) . 'Resource'; if (class_exists($resourceClass)) { $pageTitle = $resourceClass::getNavigationLabel() ?? $resourceClass::getTitle() ?? null; } } // Pattern: filament.admin.pages.{page} elseif (preg_match('/filament\.admin\.pages\.(.+)/', $routeName, $matches)) { $pageName = $matches[1]; $pageClass = 'App\\Filament\\Pages\\' . str_replace(' ', '', ucwords(str_replace(['-', '_'], ' ', $pageName))); if (class_exists($pageClass)) { if (method_exists($pageClass, 'getNavigationLabel')) { $pageTitle = $pageClass::getNavigationLabel(); } elseif (isset($pageClass::$navigationLabel)) { $pageTitle = $pageClass::$navigationLabel; } } } } } catch (\Exception $e) { // Ignore errors } } } // Always show title if detected (unless explicitly disabled) $shouldShowTitle = $showTitle !== false && !empty($pageTitle); // Debug logging (can be removed later) if (config('app.debug') && $shouldShowTitle) { \Log::debug('Breadcrumb component: Page title detected', [ 'pageTitle' => $pageTitle, 'showTitle' => $showTitle, 'shouldShowTitle' => $shouldShowTitle, 'hasThis' => isset($this), ]); } // Ensure breadcrumbs is an array and each item is separate // If we got a single item with a combined title like "Product - Create Product", split it if (count($breadcrumbs) === 1 && isset($breadcrumbs[0]['title'])) { $combinedTitle = $breadcrumbs[0]['title']; $originalUrl = $breadcrumbs[0]['url'] ?? null; if (strpos($combinedTitle, ' - ') !== false) { // Split the combined title and rebuild breadcrumbs $titleParts = explode(' - ', $combinedTitle); $newBreadcrumbs = []; foreach ($titleParts as $index => $part) { $isLast = $index === count($titleParts) - 1; $newBreadcrumbs[] = [ 'title' => trim($part), 'url' => $isLast ? $originalUrl : null, 'is_active' => $isLast, ]; } $breadcrumbs = $newBreadcrumbs; } } // Debug: Log breadcrumbs if in debug mode (remove after testing) if (config('app.debug') && count($breadcrumbs) > 0) { \Log::debug('Breadcrumb component received breadcrumbs', [ 'count' => count($breadcrumbs), 'breadcrumbs' => $breadcrumbs, ]); } @endphp @if(count($breadcrumbs) > 0 || $shouldShowTitle) @endif