yasiao / laravel-breadcrumb by yasiao

A simple breadcrumbs generator.
1,430
1
2
Package Data
Maintainer Username: yasiao
Maintainer Contact: syj610226@gmail.com (Ya-Jie Siao)
Package Create Date: 2016-09-03
Package Last Update: 2022-05-06
Language: PHP
License: MIT
Last Refreshed: 2024-11-18 03:04:58
Package Statistics
Total Downloads: 1,430
Monthly Downloads: 17
Daily Downloads: 0
Total Stars: 1
Total Watchers: 2
Total Forks: 0
Total Open Issues: 0

Laravel-Breadcrumb

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') !!}