定制 zaichaopan/breadcrumb 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

zaichaopan/breadcrumb

Composer 安装命令:

composer require zaichaopan/breadcrumb

包简介

A package to add dynamic breadcrumb to your laravel app

README 文档

README

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.

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.

// 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.

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.

To implement the interface in the model:

// 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.

To include in your products.show view:

@include('breadcrumb::_nav')

If you want to customize the breadcrumb nav. You can publish the view.

php artisan vendor:publish

Then choose the provider: Zaichaopan\Breadcrumb\BreadcrumbServiceProvider

That is all you need to do to use this package.

统计信息

  • 总下载量: 1
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-06-21

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固