定制 saucebase/breadcrumbs 二次开发

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

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

saucebase/breadcrumbs

Composer 安装命令:

composer require saucebase/breadcrumbs

包简介

Minimal breadcrumbs package for Saucebase — a fork of diglactic/laravel-breadcrumbs without Blade rendering.

README 文档

README

Breadcrumb definitions for Laravel applications that serve breadcrumbs as data, not HTML.

Installation

composer require saucebase/breadcrumbs

Defining breadcrumbs

Create routes/breadcrumbs.php and define breadcrumbs by route name:

use Saucebase\Breadcrumbs\Breadcrumbs;
use Saucebase\Breadcrumbs\Generator as Trail;

Breadcrumbs::for('home', function (Trail $trail) {
    $trail->push('Home', route('home'));
});

Breadcrumbs::for('dashboard', function (Trail $trail) {
    $trail->parent('home');
    $trail->push('Dashboard', route('dashboard'));
});

// Route model binding
Breadcrumbs::for('post.show', function (Trail $trail, Post $post) {
    $trail->parent('dashboard');
    $trail->push($post->title, route('post.show', $post));
});

Each push() call accepts an optional third argument — an array of arbitrary attributes passed through to the breadcrumb item:

$trail->push('Label', $url, ['icon' => 'home']);

Generating breadcrumbs

// Check if a breadcrumb exists for the current route
Breadcrumbs::exists('dashboard');

// Generate for the current route (reads from request)
$items = Breadcrumbs::current();

// Generate for a named route with parameters
$items = Breadcrumbs::generate('post.show', $post);

Each item in the returned collection has title, url, and attributes properties.

Hooks

Use before() and after() to prepend or append items globally across all breadcrumb chains:

// Prepend an item to every breadcrumb trail
Breadcrumbs::before(function (Trail $trail) {
    $trail->push('Home', route('home'));
});

// Append an item to every breadcrumb trail
Breadcrumbs::after(function (Trail $trail) {
    $trail->push('Help', route('help'));
});

Config

Publish the config file with:

php artisan vendor:publish --tag=breadcrumbs-config
Key Default Description
files base_path('routes/breadcrumbs.php') File(s) where breadcrumbs are defined
unnamed-route-exception true Throw UnnamedRouteException when the current route has no name
missing-route-bound-breadcrumb-exception true Throw InvalidBreadcrumbException when no breadcrumb is registered for the current route
invalid-named-breadcrumb-exception true Throw InvalidBreadcrumbException when calling generate() with an unregistered name

Testing

Override the current route in tests without making real HTTP requests:

use Saucebase\Breadcrumbs\Breadcrumbs;

// Set the route that Breadcrumbs::current() will resolve against
Breadcrumbs::setCurrentRoute('post.show', $post);

$items = Breadcrumbs::current();

// Reset after the test
Breadcrumbs::clearCurrentRoute();

Exceptions

Exception Thrown when
UnnamedRouteException The current route has no name and unnamed-route-exception is true
InvalidBreadcrumbException A breadcrumb name is not registered and the relevant config exception is true
DuplicateBreadcrumbException Breadcrumbs::for() is called with a name that is already registered

This package is a fork of diglactic/laravel-breadcrumbs with Blade rendering removed. The render() / view() methods, the manager-class / generator-class config options, and the facade/ignition-contracts dependency have been stripped. Everything else is preserved.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-03-20

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固