Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Breadcrumbs Laravel Package

diglactic/laravel-breadcrumbs

Laravel-style breadcrumbs for your app. Define trails in a single place, render them with built-in or custom templates, and support route-bound crumbs and structured data. Official fork of Dave James Miller’s original Laravel Breadcrumbs.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps

  1. Installation: Run composer require diglactic/laravel-breadcrumbs to add the package.
  2. Define Breadcrumbs: Create routes/breadcrumbs.php and define breadcrumb trails using Breadcrumbs::for(). Example:
    Breadcrumbs::for('home', function ($trail) {
        $trail->push('Home', route('home'));
    });
    
  3. Render in Views: Use {{ Breadcrumbs::render('home') }} in your Blade templates.

First Use Case

For a blog post page, define dynamic breadcrumbs:

// routes/breadcrumbs.php
Breadcrumbs::for('post', function ($trail, $post) {
    $trail->parent('blog');
    $trail->push($post->title, route('post', $post));
});

Render in Blade:

{{ Breadcrumbs::render('post', $post) }}

Implementation Patterns

Core Workflow

  1. Define Trails: Use Breadcrumbs::for() to map route names to breadcrumb logic.
  2. Parent-Child Relationships: Chain breadcrumbs with $trail->parent('parent-name') and $trail->push().
  3. Dynamic Data: Pass model instances or variables to closures for dynamic titles/URLs.

Integration Tips

  • Route-Bound Breadcrumbs: Align breadcrumb names with route names to auto-render breadcrumbs via middleware:
    // app/Http/Middleware/BreadcrumbsMiddleware.php
    public function handle($request, Closure $next) {
        Breadcrumbs::render(request()->route()->getName());
        return $next($request);
    }
    
  • View Composition: Use Breadcrumbs::view() for structured data (e.g., JSON-LD) alongside standard views.
  • Custom Views: Extend built-in templates by publishing views:
    php artisan vendor:publish --tag=breadcrumbs-views
    

Advanced Patterns

  • Nested Categories: Recursively build trails for hierarchical data:
    Breadcrumbs::for('category', function ($trail, $category) {
        if ($category->parent) {
            $trail->parent('category', $category->parent);
        } else {
            $trail->parent('blog');
        }
        $trail->push($category->name, route('category', $category));
    });
    
  • Conditional Logic: Use closures to conditionally set breadcrumbs:
    Breadcrumbs::for('dashboard', function ($trail) {
        if (auth()->check()) {
            $trail->push('Dashboard', route('dashboard'));
        } else {
            $trail->push('Login', route('login'));
        }
    });
    

Gotchas and Tips

Pitfalls

  1. Missing Route Names: Ensure routes are named (Route::name()) for route-bound breadcrumbs to work.
  2. View Path Errors: Verify custom view paths in config/breadcrumbs.php match your Blade files.
  3. Circular Dependencies: Avoid recursive parent calls that create infinite loops (e.g., parent('category') where category depends on itself).

Debugging

  • Check Definitions: Use Breadcrumbs::generate('name', $params) in Tinker to inspect breadcrumb collections:
    php artisan tinker
    >>> Breadcrumbs::generate('post', $post)
    
  • Clear Cache: After config changes, run:
    php artisan config:clear
    php artisan view:clear
    

Tips

  • SEO Optimization: Combine with JSON-LD for structured data:
    {{ Breadcrumbs::view('breadcrumbs::json-ld', 'post', $post) }}
    
  • Tailwind CSS: Use the built-in Tailwind template for utility-first styling:
    'view' => 'breadcrumbs::tailwind',
    
  • Custom Data: Attach metadata to breadcrumbs for extended views:
    $trail->push('Post', route('post'), ['author' => $post->user->name]);
    
  • Middleware Integration: Auto-render breadcrumbs in a middleware:
    public function handle($request, Closure $next) {
        if ($request->route()->getName()) {
            Breadcrumbs::render($request->route()->getName());
        }
        return $next($request);
    }
    
  • Performance: Cache breadcrumb definitions in a service provider’s boot() method if used across many routes.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
codraw/framework-extra-bundle
codraw/messenger
codraw/security
codraw/mailer
codraw/contracts
codraw/profiling
codraw/dependency-injection
codraw/tester
codraw/core
nexmo/api-specification
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony