$ show diglactic/laravel-breadcrumbs
This is a Laravel package that provides a simple, flexible way to define and render breadcrumbs in Laravel applications. It allows developers to define breadcrumb trails using closures in a dedicated file (routes/breadcrumbs.php by default), supporting parent-child relationships, route-bound breadcrumbs, custom data, before/after callbacks, and macros. The package generates a collection of breadcrumb objects and renders them using Blade views, with built-in templates for Bootstrap 4/5, Bulma, Foundation 6, JSON-LD structured data, Materialize, Tailwind CSS, and UIkit. The architecture consists of a Manager singleton that orchestrates registration and rendering, a Generator class that recursively builds the breadcrumb trail by calling user-defined closures, and a Facade for convenient access. The codebase is well-structured, thoroughly tested (30+ test files), and includes helpful exception handling with Laravel Ignition solutions. It is actively maintained and supports Laravel 10 through 13 with PHP 8.1+.
The LLM identified 4 files worth highlighting for reuse:
The Generator class is the core engine that builds a breadcrumb collection by recursively calling user-registered closures. It demonstrates a clean pattern of accepting callbacks, before/after hooks, and a name with parameters, then iterating through parent references via the `parent()` method. The `push()` method adds breadcrumb objects with title, URL, and optional custom data. This component is reusable as a standalone breadcrumb generator if the Laravel-specific dependencies are replaced, and its design pattern (callback-based trail building) can be adapted for other hierarchical navigation systems.
The Manager class serves as the central service for registering, generating, and rendering breadcrumbs. It uses Laravel's Macroable trait to allow extension, and it manages the callbacks, before/after hooks, and current route state. The class demonstrates a clean separation of concerns: registration (`for`, `before`, `after`), generation (`generate`), rendering (`view`, `render`), and route management (`setCurrentRoute`, `clearCurrentRoute`). It also handles exception configuration via Laravel's config. This pattern is reusable for any Laravel package that needs a singleton service with macroable capabilities.
This exception class implements Laravel Ignition's ProvidesSolution interface to offer actionable solutions when a breadcrumb is not found. It dynamically generates a code snippet suggestion based on the current route and config file paths. This pattern of providing context-aware solutions for common errors is a best practice for Laravel packages and can be reused in any package that wants to improve developer experience.
A clean Blade template for rendering breadcrumbs with Bootstrap 5 markup, including proper ARIA attributes (`aria-label`, `aria-current`). It iterates over the `$breadcrumbs` collection and conditionally renders links or active items. This template is reusable as a starting point for any Laravel project using Bootstrap 5, and the pattern of checking `$loop->last` and `$breadcrumb->url` is standard for breadcrumb rendering.