- How do I install and set up Laravel Breadcrumbs in my project?
- Run `composer require tabuna/breadcrumbs` to install. Define breadcrumbs directly in route files using the `breadcrumbs()` method with a closure accepting a `Trail` object. No additional configuration is needed for basic usage.
- Can I use Eloquent models or request parameters in breadcrumb generation?
- Yes. The package supports model binding and named parameters. For example, pass a `Category` model to your closure and use `$category->title` or `route('category', $category->id)` to dynamically generate breadcrumbs.
- What Laravel versions does this package support?
- The package requires Laravel 10+ and PHP 8.1+. Named parameter resolution relies on Laravel’s container improvements, so downgrading to Laravel 9.x will break functionality. Always pin to `5.x` in `composer.json` to avoid unintended upgrades.
- How do I create nested breadcrumb trails (e.g., Home > Category > Product)?
- Use the `parent()` method to reference existing trails. For example, `$trail->parent('home')->push('Category', route('category'))` builds on the 'home' trail. The package automatically handles route detection for cleaner code.
- Will this package work with my custom route generators?
- Yes, but refactoring may be needed if you’re using `Trail::call()` directly. Replace it with `app()->call()` or dependency injection via constructor. The package now enforces stricter encapsulation to prevent misuse of internal methods.
- How do I test breadcrumb functionality in my Laravel app?
- Test breadcrumbs by asserting route names, parameters, and generated HTML in your feature tests. Use `Trail::get()` to inspect trails or mock the `Trail` object in unit tests. The package includes 100% mutation testing coverage for reliability.
- Are there performance concerns with named parameter resolution?
- Minimal overhead exists due to Laravel’s container dependency injection, but it’s negligible for most use cases. If you’re micro-optimizing, benchmark in staging. Caching strategies may need review if breadcrumbs use `Cache::tags()`.
- Can I use this package with non-Laravel PHP applications?
- No. The package relies on Laravel’s route system, container, and Blade components. For non-Laravel apps, consider alternatives like manual HTML generation or custom breadcrumb libraries for vanilla PHP.
- What alternatives exist for Laravel breadcrumbs?
- Alternatives include `diglactic/laravel-breadcrumbs` (simpler but less feature-rich) or `spatie/laravel-menu` (for menus + breadcrumbs). This package stands out for its fluent API, route parameter support, and automatic route detection.
- How do I migrate from older versions if I’m using `Trail::call()`?
- Replace `Trail::call()` with `app()->call()` or refactor to use dependency injection via constructor. The package’s `hasMacro` guard prevents accidental macro overwrites, but no deprecation warnings exist for positional arguments—test thoroughly after upgrading.