2017 © Pedro Peláez
 

library breadcrumb

A package to add dynamic breadcrumb to your laravel app

image

zaichaopan/breadcrumb

A package to add dynamic breadcrumb to your laravel app

  • Sunday, June 24, 2018
  • by zaichaopan
  • Repository
  • 1 Watchers
  • 0 Stars
  • 1 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Breadcrumb

This package allows you to add dynamic breadcrumb to your laravel app. It is inspired by code course. It can be used in laravel 5.5 or higher., (*1)

Installation

composer require zaichaopan/breadcrumb

Usage

  • Implement BreadcrumbLinkInterface in your eloquent model which you want to use to generate breadcrumb.

To better understand how to use this package. Consider the following example: your app can list different products which may belong to different categories., (*2)

// web.php
Route::get('/categories/{category}/products/{product}', 'ProductsController@show');
// ...
class ProductsController extends Controller
{
    public function show(Category $category, Product $product)
    {
        // ...
        return view('product.show', compact('product'));
    }
}

To generate the breadcrumb link in the products.show view. You need to implement the BreadcrumbLinkInterface in your Category and Product model., (*3)

There is only one method in the BreadcrumbLinkInterface : LinkText. It is used to define the text of the link when generating the breadcrumb. This package needs to know it because you may have model id in the url or you may replace the id with uuid or slug in the url. We don't want to use any one of them for the text for the url when generating the breadcrumb., (*4)

To implement the interface in the model:, (*5)

// Category.php
class Category extends Model implements BreadcrumbLinkInterface
{
    public function linkText() : string
    {
        // you want to display category name in the breadcrumb link
        return $this->name;
    }
}
// Product.php
class Product extends Model implements BreadcrumbLinkInterface
{

    public function linkText(): string
    {
         // you want to display product name in the breadcrumb link
        return $this->name;
    }
}
  • Include breadcrumb nav link in the view

This package provides a default bootstrap4-style breadcrumb nav partial view., (*6)

To include in your products.show view:, (*7)

@include('breadcrumb::_nav')

If you want to customize the breadcrumb nav. You can publish the view., (*8)

php artisan vendor:publish

Then choose the provider: Zaichaopan\Breadcrumb\BreadcrumbServiceProvider, (*9)

That is all you need to do to use this package., (*10)

The Versions

24/06 2018

dev-master

9999999-dev

A package to add dynamic breadcrumb to your laravel app

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar zaichaopan

laravel breadcrumb

22/06 2018

v0.1-beta

0.1.0.0-beta

A package to add dynamic breadcrumb to your laravel app

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar zaichaopan

laravel breadcrumb