- How do I install diglactic/laravel-breadcrumbs in a Laravel project?
- Run `composer require diglactic/laravel-breadcrumbs` to install the package. Publish the configuration file with `php artisan vendor:publish --provider="Diglactic\Breadcrumbs\BreadcrumbsServiceProvider"` if you need to customize defaults. The package is ready to use after installation.
- What Laravel versions does this package support?
- The package supports Laravel 7 through 13, with version-specific compatibility (e.g., Laravel 13 requires version 10.x). Check the [compatibility chart](https://github.com/diglactic/laravel-breadcrumbs#compatibility-chart) for exact mappings. Older versions may require the original package.
- Can I define breadcrumbs dynamically, like using Eloquent models or user-specific data?
- Yes, you can pass dynamic data to breadcrumbs using closures. For example, `->parent('Parent', function () { return Model::find(1)->name; })` fetches data on demand. Just ensure the closure returns a string or HTML-safe value to avoid runtime errors.
- How do I customize the HTML output of breadcrumbs?
- Create a custom Blade template in `resources/views/vendor/breadcrumbs/your-template.blade.php` and specify it in your `config/breadcrumbs.php` under `template`. The template receives a `$breadcrumbs` variable containing an array of breadcrumb items with `url`, `title`, and `active` properties.
- Does this package support structured data like JSON-LD for SEO?
- Yes, the package includes built-in support for JSON-LD structured data. Enable it in your `config/breadcrumbs.php` by setting `'structured_data' => true`, and the package will automatically generate the required markup in your view.
- How do route-bound breadcrumbs work, and do they require special route naming?
- Route-bound breadcrumbs automatically generate trails based on route names. Use `Breadcrumbs::route('route.name')` in your controller or middleware. For consistency, name your routes descriptively (e.g., `admin.users.index` instead of `route123`).
- Will breadcrumbs impact performance in high-traffic Laravel apps?
- Breadcrumbs are generated per request by default, which is lightweight but may not be optimal for high-traffic pages. Mitigate this by caching routes (`php artisan route:cache`) or using middleware to pre-generate breadcrumbs for static paths.
- Can I use this package in a headless Laravel API or SPA?
- While the package is designed for Blade views, you can still use it in SPAs or APIs by rendering breadcrumbs as JSON or structured data. Pass the breadcrumb trail via API responses or use client-side templates to display them dynamically.
- How do I handle translations for breadcrumb titles?
- Use Laravel’s built-in translation helpers like `trans('breadcrumbs.home')` within your breadcrumb definitions. For dynamic content, combine translations with closures, e.g., `->parent(trans('breadcrumbs.category'), function () { return Category::find($id)->name; })`.
- Are there alternatives to diglactic/laravel-breadcrumbs for Laravel?
- Alternatives include `spatie/laravel-breadcrumbs` (a more opinionated package with a different API) or `artesaos/seotools` (which includes breadcrumb functionality as part of a broader SEO suite). This package stands out for its Laravel-native design and minimal setup, making it ideal for projects prioritizing simplicity and SEO.