Laravel Breadcrumbs - An easy way to add breadcrumbs to your @Laravel app.

Overview

Laravel Breadcrumbs

Tests codecov Total Downloads Latest Version on Packagist

Introduction

Breadcrumbs display a list of links indicating the position of the current page in the whole site hierarchy. For example, breadcrumbs like Home / Sample Post / Edit means the user is viewing an edit page for the "Sample Post." He can click on "Sample Post" to view that page or click on "Home" to return to the homepage.

Home / Sample Post / Edit

This package for the Laravel framework will make it easy to build breadcrumbs in your application.

Installation

Run this at the command line:

$ composer require tabuna/breadcrumbs

This will update composer.json and install the package into the vendor/ directory.

Define your breadcrumbs

Now you can define breadcrumbs directly in the route files:

use Tabuna\Breadcrumbs\Trail;

// Home
Route::get('/', fn () => view('home'))
    ->name('home')
    ->breadcrumbs(fn (Trail $trail) =>
        $trail->push('Home', route('home'))
);

// Home > About
Route::get('/about', fn () => view('home'))
    ->name('about')
    ->breadcrumbs(fn (Trail $trail) =>
        $trail->parent('home')->push('About', route('about'))
);

You can also get arguments from the request:

Route::get('/category/{category}', function (Category $category){
    //In this example, the category object is your Eloquent model.
    //code...
})
    ->name('category')
    ->breadcrumbs(fn (Trail $trail, Category $category) =>
        $trail->push($category->title, route('category', $category->id))
);

Route detection

The package tries to reduce the number of lines needed. For this, you can skip passing the results of the route() methods. The following two declarations will be equivalent:

Route::get('/', fn () => view('home'))
    ->name('home')
    ->breadcrumbs(fn (Trail $trail) =>
        $trail->push('Home', route('home'))
);

Route::get('/', fn () => view('home'))
    ->name('home')
    ->breadcrumbs(fn (Trail $trail) =>
        $trail->push('Home', 'home')
);

Like to use a separate route file?

You can do this simply by adding the desired file to the service provider

namespace App\Providers;

use Illuminate\Support\ServiceProvider;

class BreadcrumbsServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap the application events.
     *
     * @return void
     */
    public function boot()
    {
        require base_path('routes/breadcrumbs.php');
    }
}

Then it will be your special file in the route directory:

// routes/breadcrumbs.php


// Photos
Breadcrumbs::for('photo.index', fn (Trail $trail) =>
    $trail->parent('home')->push('Photos', route('photo.index'))
);

Route resource

When using resources, a whole group of routes is declared for which you must specify values manually

// routes/web.php

Route::resource('photos', 'PhotoController');

It’s better to specify this in service providers, since route files can be cached

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Tabuna\Breadcrumbs\Breadcrumbs;
use Tabuna\Breadcrumbs\Trail;

class BreadcrumbsServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        Breadcrumbs::for('photos.index', fn (Trail $trail) =>
             $trail->push('Photos', route('home'))
        );
        
        Breadcrumbs::for('photos.create', fn (Trail $trail) =>
            $trail
                ->parent('photos.index', route('photos.index'))
                ->push('Add new photo', route('home'))
        );
    }
}

Output the breadcrumbs use Blade Component

You can use the output component:

<ul>
    <x-tabuna-breadcrumbs/>
ul>

To define classes of list items, you can specify:

">
<x-tabuna-breadcrumbs
  class="item"
  active="active"
/>

You can also pass parameters:

">
<x-tabuna-breadcrumbs
    parameters="['value 1', 'value 2', 'value 3']"
/>

And call named routes explicitly:

">
<x-tabuna-breadcrumbs
    route="static"
/>

Output the breadcrumbs use Blade view

In order to display breadcrumbs on the desired page, simply call:

{{ $crumbs->title() }} @else @endif @endforeach @endif ">
@if(Breadcrumbs::has())
    @foreach (Breadcrumbs::current() as $crumbs)
        @if ($crumbs->url() && !$loop->last)
            <li class="breadcrumb-item">
                <a href="{{ $crumbs->url() }}">
                    {{ $crumbs->title() }}
                a>
            li>
        @else
            <li class="breadcrumb-item active">
                {{ $crumbs->title() }}
            li>
        @endif
    @endforeach
@endif

And results in this output:

Home / About

Credits

For several years, I successfully used the Dave James Miller package to solve my problems, but he stopped developing and supporting it. After a long search for alternatives, I liked the Dwight Watson package, but the isolation of breadcrumbs from the announcement of the routes did not give me rest. That's why I created this package. It uses the code of both previous packages.

License

The MIT License (MIT). Please see License File for more information.

Comments
  • Error when using query strings.

    Error when using query strings.

    I use Livewire, and take advantage of their query string functionality.

    Whenever a query string is set, the breadcrumb package interrupts and adds a really long query string. No idea why this happens. image

    opened by mattcookdev 8
  • multi tenancy app

    multi tenancy app

    Multi-tenancy is the ability to provide your service to multiple users (tenants) from a single hosted instance of the application. This is contrasted with deploying the application separately for each user.

    i got this error Breadcrumbs have already been defined for route [admin.dashboard]. while integrating the package to my multi tenancy app. there seems to be a compatibility issue with multi tenancy package. can you take a look at it

    bug 
    opened by netwrkx 5
  • Laravel 9.x Compatibility

    Laravel 9.x Compatibility

    This is an automated pull request from Shift to update your package code and dependencies to be compatible with Laravel 9.x.

    Before merging, you need to:

    • Checkout the l9-compatibility branch
    • Review all comments for additional changes
    • Thoroughly test your package

    If you do find an issue, please report it by commenting on this PR to help improve future automation.

    opened by laravel-shift 4
  • Using Livewire routes macro it push the breadcrumb three times

    Using Livewire routes macro it push the breadcrumb three times

    Using the following code in the web.php file:

    Route::livewire('dashboard', 'dashboard')->name('home')
            ->breadcrumbs(fn (Trail $trail) => $trail->push("Dashboard", route("home")) && \Illuminate\Support\Facades\Log::debug('Dashboard pushed'));
    

    You'll get the follow logs output:

    [2020-09-01 18:25:53] local.DEBUG: Dashboard pushed  
    [2020-09-01 18:25:53] local.DEBUG: Dashboard pushed  
    [2020-09-01 18:25:53] local.DEBUG: Dashboard pushed  
    

    It means that the breadcrumb pushed three times, and the title will be wrong.

    opened by masterix21 4
  • Laravel's serializable closures

    Laravel's serializable closures

    Hello, thanks for the package.

    The Laravel team recently decided to fork the opis/closure package because v4 is being rewritten on top of the FFI extension which will not be enabled by default on all distros.

    Are you willing to accept PRs to drop the opis/closure dependency in this package in favor of the first party Laravel package?

    opened by mabdullahsari 2
  • 502 Bad Gateway

    502 Bad Gateway

    Hi when i used

    i received 502 Bad Gateway, and no error registered in log files, how can i resolve this or how can i detect the error

    thank you

    opened by abdosaeedelhassan 2
  • My implementation is showing no divider. How can I use f.e

    My implementation is showing no divider. How can I use f.e "<" as a divider?

    Hello there,

    This is what my front looks like: https://i.gyazo.com/0585fdb66bbd34e79ab15ad1b5cc2a0c.png

    Here's the implementation: https://i.gyazo.com/f9ac2441d1c80220f8724b8a27550355.png

    Is there a way to use "<" as a divider?

    I can push it through in the routes file, but that doesn't really seem clean: https://i.gyazo.com/54cd557edbb082536f4e46474ce3bff6.png

    opened by aFluxx 2
  • White space at end of links

    White space at end of links

    There is a white space displayed at the end of each link inside the breadcrumbs.

    This space is caused by the new lines in the view (breadcrumbs.blade.php)

    <a href="{{ $crumbs->url() }}">
    {{ $crumbs->title() }}
    </a>
    
    opened by dividy 2
  • fail silently?

    fail silently?

    I'm trying to integrate a legacy application with Laravel. What I have is a combination of pages, ones that use the new tabuna/breadcrumbs version and some previously written breadcrumbs that are outside of Laravel routes.

    On my legacy pages where I do not want to use tabuna/breadcrumbs but I still want to use the blade templates. This is where my issue comes in. If I call Breadcrumbs::current() in my layout template I get Argument 1 passed to Tabuna\Breadcrumbs\Manager::generate() must be of the type string, null given, called in vendor/tabuna/breadcrumbs/src/Manager.php on line 59. Is there a way to fail silently? Without putting a try/catch block in the blade template?

    opened by jamesj2 2
  • LogicException Route is not bound

    LogicException Route is not bound

    Laravel version: 7.20.0 Package version: 1.3.0

    I declared breadcrumbs in separate file (routes/breadcrumbs.php) and after php artisan route:cache I get this exception:

    image

    app/Providers/BreadcrumbsServiceProvider.php

    namespace App\Providers;
    
    use Illuminate\Support\ServiceProvider;
    
    class BreadcrumbsServiceProvider extends ServiceProvider
    {
        /**
         * Bootstrap the application events.
         *
         * @return void
         */
        public function boot()
        {
            require base_path('routes/breadcrumbs.php');
        }
    }
    

    config/app.php

            /*
             * Application Service Providers...
             */
            App\Providers\AppServiceProvider::class,
            App\Providers\AuthServiceProvider::class,
            App\Providers\BreadcrumbsServiceProvider::class,
            // App\Providers\BroadcastServiceProvider::class,
            App\Providers\EventServiceProvider::class,
            App\Providers\HorizonServiceProvider::class,
            App\Providers\TelescopeServiceProvider::class,
            App\Providers\RouteServiceProvider::class,
    

    Example of my code:

    Breadcrumbs::for('events.index', function ($trail) {
        $trail->parent('deedee');
        $trail->push('Events', route('events.index'));
    });
    
    Breadcrumbs::for('events.create', function ($trail) {
        $trail->parent('events.index');
        $trail->push('Create', route('events.create'));
    });
    
    Breadcrumbs::for('events.show', function ($trail, $event) {
        $trail->parent('events.index');
        $trail->push('Show', route('events.show', $event));
    });
    
    Breadcrumbs::for('events.edit', function ($trail, $event) {
        $trail->parent('events.index');
        $trail->push('Edit', route('events.edit', $event));
    });
    

    Without cached routes it works fine. What am I missing?

    opened by NebsterSK 2
  • Added blade component

    Added blade component

    Hey. I think it would be nice to have a component for determining breadcrumbs directly from the package.

    It would be a straightforward definition, for example:

    <x-tabuna-breadcrumbs/>
    

    To define classes of list items, you can specify:

    <x-tabuna-breadcrumbs
      class="item"
      active="active"
    />
    

    You can also pass parameters:

    <x-tabuna-breadcrumbs
        parameters="['value 1', 'value 2', 'value 3']"
    />
    

    And call named routes explicitly:

    <x-tabuna-breadcrumbs
        route="static"
    />
    
    enhancement 
    opened by tabuna 1
  • I can not send parameter to Breadcrumb

    I can not send parameter to Breadcrumb

    Dear All Friend,

    Firstly I want to say thank you for your help.

    I am using breadcrumbs in my project. There is no problem in pages where I dont send parameter. But when i want to send parameter, I dont taking anything. You can see below detail code in my project

    BreadCrumbsServiceProvider

    require base_path('routes/breadcrumbs.php'); // (I regestered this file in config/app)
    

    breadcrumbs.php

    // Setting ->There is no problem
    Breadcrumbs::for('admin.setting.index', fn(Trail $trail) => $trail
        ->parent('admin.dashboard')
        ->push('Site Ayarları', route('admin.setting.index'))
    );
    // Client Detail->There is huge problem for me :)
    Breadcrumbs::for('admin.client.detail/{id}', fn(Trail $trail, Client $client) => $trail
        ->parent('admin.musteri.index', route('admin.musteri.index'))
        ->push($client->id . ' Nolu Müşteri Detayı', route('admin.client.detail', $client->id))
    );
    

    You think, what should I do?

    opened by sametsahin 8
  • Breadcrumbs are not displaying inline

    Breadcrumbs are not displaying inline

    Good Day, Please excuse me if I am wrong, I am still a junior developer. I would like to make note of an issue that I have found and provide a fix.

    Implementing what is provided, the outcome is having each <li> on a new line:

    @if(Breadcrumbs::has())
        @foreach (Breadcrumbs::current() as $crumbs)
            @if ($crumbs->url() && !$loop->last)
                <li class="breadcrumb-item">
                    <a href="{{ $crumbs->url() }}">
                        {{ $crumbs->title() }}
                    </a>
                </li>
            @else
                <li class="breadcrumb-item active">
                    {{ $crumbs->title() }}
                </li>
            @endif
        @endforeach
    @endif
    

    View of display:

    Screenshot_2020-11-19 Edit Book Gouws Freeway · Electronic Library Assistant

    In order to display the breadcrumbs inline I have to add the <ol> tag back from "tabuna/breadcrumbs": "^1.0" and this seems to be working:

            @if(Breadcrumbs::has())
              <ol class="breadcrumb border-0 m-0">
                @foreach (Breadcrumbs::current() as $crumbs)
                  @if ($crumbs->url() && !$loop->last)
                    <li class="breadcrumb-item">
                      <a href="{{ $crumbs->url() }}">
                        {{ $crumbs->title() }}
                      </a>
                    </li>
                  @else
                    <li class="breadcrumb-item active">
                      {{ $crumbs->title() }}
                    </li>
                  @endif
                @endforeach
              </ol>
            @endif
    

    View of working display: Screenshot_2020-11-19 Edit Book Gouws Freeway · Electronic Library Assistant(1)

    Thank you.

    opened by getlashified 0
  • Argument 2 passed to App\Providers\BreadcrumbsServiceProvider

    Argument 2 passed to App\Providers\BreadcrumbsServiceProvider

    I'm getting this error:

    Argument 2 passed to App\Providers\BreadcrumbsServiceProvider::App\Providers{closure}() must be an instance of App\Models\project\Project, string given (View: /var/www/resources/views/navigation/breadcrumbs.blade.php)

    In app/Providers/BreadcrumbsServiceProvider.php

    <?php
    
    namespace App\Providers;
    
    use Tabuna\Breadcrumbs\Trail;
    use App\Models\project\Project;
    use Tabuna\Breadcrumbs\Breadcrumbs;
    use Illuminate\Support\ServiceProvider;
    
    class BreadcrumbsServiceProvider extends ServiceProvider
    {
        /**
         * Bootstrap any application services.
         *
         * @return void
         */
        public function boot()
        {
            Breadcrumbs::for('home', fn (Trail $trail) =>
            $trail->push('Dashboard', route('home')));
    
            Breadcrumbs::for('project.index', fn (Trail $trail) =>
            $trail->parent('home', route('home'))
                ->push('Projects', route('project.index')));
    
            Breadcrumbs::for('project.show', fn (Trail $trail, Project $project) =>
            $trail->parent('project.index', route('project.index'))
                ->push('View Project', route('project.show', compact('project'))));
    
            Breadcrumbs::for('project.bill.index', fn (Trail $trail, Project $project) =>
            $trail->parent('project.show', route('project.show', compact('project')))
                ->push('View Bills', route('project.bill.index', compact('project'))));
        }
    }
    
    

    in resources/views/navigation/breadcrumbs.blade.php

    <div class="col-md-12">
        <div class="row">
            @if(Breadcrumbs::has())
            @foreach (Breadcrumbs::current() as $crumbs)
            @if ($crumbs->url() && !$loop->last)
            <li class="breadcrumb-item" style="list-style-type: none;">
                <a href="{{ $crumbs->url() }}">
                    {{ $crumbs->title() }}
                </a>
            </li>
            @else
            <li class="breadcrumb-item active" style="list-style-type: none;">
                {{ $crumbs->title() }}
            </li>
            @endif
            @endforeach
            @endif
        </div>
    </div>
    

    I can't seem to figure out what I'm doing wrong. It works fine until I visit project.bill.index

    My routes are defined as:

    ...
    Route::resource('project', 'project\ProjectController'); // Project Crud
    ...
    ...
    Route::resource('project.bill', 'project\bill\BillController'); // Bill Crud
    ...
    
    opened by fbc 6
  • Error on Manager.php:59

    Error on Manager.php:59

    Hello,

    I have an error when I try to show route list in command line : image

    All my breadcrumbs are defined in a file in routes/breadcrumbs.php as described in documentation.

    Did someone else already had this error ?

    opened by ptifloflo 0
  • Argument 2 passed to {closure}() must be an instance of

    Argument 2 passed to {closure}() must be an instance of

    closure://function (\Tabuna\Breadcrumbs\Trail $trail, \App\Models\Backend\Chamber $chamber) { $trail->parent('admin.chambers.index') ->push(__('Editing :chamber', ['chamber' => $chamber->id]), route('admin.chambers.edit', $chamber)); }:2

    opened by akshay13aac 2
Releases(3.0.0)
Owner
Alexandr Chernyaev
Creator of @orchidsoftware, @sajya, @cagilo. Self-employed. Back-end developer.
Alexandr Chernyaev
Gretel is a Laravel package for adding route-based breadcrumbs to your application.

Gretel Laravel breadcrumbs right out of a fairy tale. Gretel is a Laravel package for adding route-based breadcrumbs to your application. Defining Bre

Galahad 131 Dec 31, 2022
An easy way to add colors in your CLI scripts.

COLORS Here is a preview of what you can achieve with the library: Installation Installation via composer is highly recommended. { "require": {

Kevin Le Brun 335 Dec 4, 2022
Laravel-tagmanager - An easier way to add Google Tag Manager to your Laravel application.

Laravel TagManager An easier way to add Google Tag Manager to your Laravel application. Including recommended GTM events support. Requirements Laravel

Label84 16 Nov 23, 2022
Add tags and taggable behaviour to your Laravel app

Add tags and taggable behaviour to a Laravel app This package offers taggable behaviour for your models. After the package is installed the only thing

Spatie 1.4k Dec 29, 2022
Add Webhooks to your Laravel app, arrr

# Captain Hook ## Add Webhooks to your Laravel app, arrr Implement multiple webhooks into your Laravel app using the Laravel Event system. A webhook i

Marcel Pociot 334 Dec 12, 2022
Entrust is a succinct and flexible way to add Role-based Permissions to Laravel 5.

ENTRUST (Laravel 5 Package) Entrust is a succinct and flexible way to add Role-based Permissions to Laravel 5. If you are looking for the Laravel 4 ve

Zizaco 6.1k Dec 31, 2022
A simple way to add 301/302 redirects within CraftCMS.

Redirector plugin for Craft CMS 3.x A simple way to add 301/302 redirects within CraftCMS. This is the first CraftCMS plugin written by myself so plea

Jae Toole 1 Nov 25, 2021
Modularize your laravel app in a package way.

Laravel Modular Pustaka laravel untuk modularisasi kode secara rapi dan mudah di maintain. Instalasi $ composer require kodepandai/laravel-modular Set

Kode Pandai 3 Jun 19, 2022
Add variables to the payload of all jobs in a Laravel app

Inject extra info to the payloads of all jobs in a Laravel app This package makes it easy to inject things in every job. Imagine that you want to have

Spatie 62 Dec 9, 2022
Laravel User Activity Log - a package for Laravel 8.x that provides easy to use features to log the activities of the users of your Laravel app

Laravel User Activity Log - a package for Laravel 8.x that provides easy to use features to log the activities of the users of your Laravel app

null 9 Dec 14, 2022
Laravel Serializable Closure provides an easy way to serialize closures in PHP.

Serializable Closure Introduction This package is a work in progress Laravel Serializable Closure provides an easy way to serialize closures in PHP. I

The Laravel Framework 316 Jan 1, 2023
An easy way to integrate Google Maps with Laravel

An easy way to integrate Google Maps with Laravel For Laravel 5.x, check version 2.35.1 For Laravel 4.x, check version 1.27.0 Think of Googlmapper as

Bradley Cornford 450 Nov 29, 2022
Easy way to upload Laravel model related files from the request.

Easy way to upload laravel model related file from the requset.

Emon Khan 5 Dec 15, 2022
Easy Way to integrate API in you laravel application.

Easy Api Easy Way to integrate API in you laravel application. Installation Guide Install Package using Composer. composer require flutterbuddy1/easy-

Mayank Diwakar 1 Oct 9, 2022
🏭 An easy way to generate populated factories for models.

Laravel Populated Factory provides an easy way to generate populated factories for models according to types & names of their columns. Install You can

Coderello 241 Nov 25, 2022
An easy way to get vendor and package data from Packagist via API calls

Laravel Packagist Laravel Packagist (LaravelPackagist) is a package for Laravel 5 to interact with the packagist api quickly and easily. Table of cont

Jeremy Kenedy 5 Jul 18, 2022
A simple blog app where a user can signup , login, like a post , delete a post , edit a post. The app is built using laravel , tailwind css and postgres

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

Nahom_zd 1 Mar 6, 2022
A web app for detecting backend technologies used in a web app, Based on wappalyzer node module

About Techdetector This a web fingerprinting application, it detects back end technologies of a given domain by using the node module wappalyzer. And

Shobi 17 Dec 30, 2022
CV-Resumes-App is helped us to build resume .. you can help me to improve this app...

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

Eng Hasan Hajjar 2 Sep 30, 2022