yasiao/laravel-breadcrumb

A simple breadcrumbs generator.

v1.2.2 2022-05-06 05:54 UTC

This package is auto-updated.

Last update: 2024-11-06 11:54:43 UTC


README

A simple breadcrumb generator.

Installation

composer require yasiao/laravel-breadcrumb

Configuration

config/app.php

providers:

Yasiao\Breadcrumb\BreadcrumbServiceProvider::class

aliases:

'Breadcrumb' => Yasiao\Breadcrumb\BreadcrumbFacade::class

config/breadcrumb.php

php artisan vendor:publish
return [
    'breadcrumb-file-path' => app_path('Http/breadcrumb.php'),
    'default-template' => 'breadcrumb::bootstrap4',
    'ignore-undefined-breadcrumb' => false
];

Base Usage

  1. Create the breadcrumb file in the "breadcrumb-file-path".

  2. Define breadcrumbs in the breadcrumb file.

    Without parameters:

    // Home
    Breadcrumb::define('home', function ($breadcrumb) {
        $breadcrumb->add('Home', action('HomeController@index'));
    });

    With a parameter:

    // Home > $category->title
    Breadcrumb::define('category', function ($breadcrumb, $category) {
        $breadcrumb->add('Home', action('HomeController@index'));
        $breadcrumb->add($category->title, $category->url);
    });

    With parameters:

    // Home > $category['title'] > $content->title
    Breadcrumb::define('content', function ($breadcrumb, $category, $content) {
        $breadcrumb->add('Home', action('HomeController@index'));
        $breadcrumb->add($category['title'], $category['url']);
        $breadcrumb->add($content->title, $content->url);
    });
  3. Render breadcrumbs.

    Without parameters:

    {!! Breadcrumbs::render('home') !!}

    With a parameter:

    {!! Breadcrumbs::render('home', $category) !!}

    With parameters:

    {!! Breadcrumbs::render('home', $category, $content) !!}

Advanced Usage

  1. The breadcrumb use the special template.

    {!! Breadcrumbs::setTemplate('bootstrap3')->render('home') !!}