Laravel Breadcrumbs


Custom Templates

Create A View

To customize the HTML, create your own view file (e.g. resources/views/partials/breadcrumbs.blade.php).

@php /** @var \Illuminate\Support\Collection $breadcrumbs **/ @endphp
@if ($breadcrumbs->isNotEmpty())
    <ol class="breadcrumb">
        @foreach ($breadcrumbs as $breadcrumb)
            @if ($breadcrumb->url && !$loop->last)
                <li class="breadcrumb-item"><a href="{{ $breadcrumb->url }}">{{ $breadcrumb->title }}</a></li>
                <li class="breadcrumb-item active">{{ $breadcrumb->title }}</li>

(See the views/ directory for the built-in templates.)

View Data

The breadcrumb view receives one parameter, $breadcrumbs, which is a Collection instance.

Each breadcrumb is an object with the following keys:

  • title – The breadcrumb title
  • url – The breadcrumb URL, or null if none was given
  • Plus additional keys for each item in $data (see Custom data)

Update The Configfiguration

Then update your config file (config/breadcrumbs.php) with the custom view name. If you have not already, you will need to publish the package configuration.

    'view' => 'partials.breadcrumbs', // resources/views/partials/breadcrumbs.blade.php

Skipping The View

Alternatively you can skip the custom view and call Breadcrumbs::generate() to get the breadcrumbs collection directly:

@foreach (Breadcrumbs::generate('post', $post) as $breadcrumb)
    {{-- ... --}}