bored-programmers/larabreadcrumb
Composer 安装命令:
composer require bored-programmers/larabreadcrumb
包简介
LaraBreadcrumb is a comprehensive Laravel package that provides an easy and flexible way to generate breadcrumbs for your Laravel applications. It supports automatic breadcrumb generation based on your routes, customization of breadcrumb titles, and hiding certain breadcrumbs.
关键字:
README 文档
README
LaraBreadcrumb is a Laravel package that simplifies the creation of breadcrumbs in Laravel applications.
NOTE
This was my first attempt at using Laravel containers and services. If you have any suggestions for improvement, please let me know.
Table of Contents
- Requirements
- Installation
- Basic Usage
- Contributing
- Changelog
- License
- Contact Information
- Credits
- Acknowledgments
Requirements
- PHP 8.1 or higher
- Laravel 10.0 or higher
Installation
To install LaraBreadcrumb, use the following command:
composer require bored-programmers/larabreadcrumb
Basic Usage
By default, LaraBreadcrumb generates breadcrumbs automatically based on the route.
It uses the route parameter values as the breadcrumb titles. For example, for a route like admin/customers/1,
it generates a breadcrumb like this: Admin / Customers / 1.
Displaying Breadcrumbs
<x-larabreadcrumb::breadcrumb/>
Customizing Breadcrumbs
For a route like Route::get('/users/{customer}'), LaraBreadcrumb generates a breadcrumb like this: Users / 1.
To customize the breadcrumb, you can use the BreadcrumbService class:
use BoredProgrammers\LaraBreadcrumb\Service\BreadcrumbService; BreadcrumbService::update() ->setAccessors([ 'customer' => fn($model) => $model->name 'customer' => fn(User $user) => $user->name 'customer' => 'name' ]); ])
This generates a breadcrumb like this: Users / John. The key customer is the name of the route parameter, and the
value is the accessor. You can use a closure or a string.
You can also add a single accessor conditionally:
use BoredProgrammers\LaraBreadcrumb\Service\BreadcrumbService; BreadcrumbService::update() ->setAccessors([ 'customer' => fn($model) => $model->name 'customer' => fn(User $user) => $user->name 'customer' => 'name' ]); ]) if (true) { BreadcrumbService::update() ->addAccessor('customer', fn($model) => $model->name); ]) }
Prefixing Breadcrumbs
By default, breadcrumbs don't have a prefix. To add a prefix to the breadcrumbs, use the BreadcrumbService class:
use BoredProgrammers\LaraBreadcrumb\Service\BreadcrumbService; # Route::get('/users/{user}/comments/{comment}'); BreadcrumbService::update() ->setPrefix('breadcrumb'); ])
This generates a breadcrumb like this: breadcrumb.users / 1 / breadcrumb.comments / 1.
Note: It's recommended to use a prefix when using translation to prevent conflicts. For example, for a route
like Route::get('admin/users'), it generates a breadcrumb like this: admin / users. This isn't a problem until you
have a translation file admin.php. Then it gives you an error array to string conversion.
Hiding Breadcrumbs
You can hide certain breadcrumbs:
use BoredProgrammers\LaraBreadcrumb\Service\BreadcrumbService; // Route::get('/users/{user}/comments/{comment}'); $breadcrumbs = BreadcrumbService::update()->hide('comments'); $breadcrumbs = BreadcrumbService::update()->hide(['comments', 'users']);
This hides the comments breadcrumb. The first result will be Users / {user} / {comment}, and the second will
be {user} / {comment}.
To hide dynamic segments, use curly braces {}:
use BoredProgrammers\LaraBreadcrumb\Service\BreadcrumbService; // Route::get('/users/{user}/comments/{comment}'); $breadcrumbs = BreadcrumbService::update()->hide('{comment}'); $breadcrumbs = BreadcrumbService::update()->hide(['{user}', '{comment}']);
This hides the dynamic segment from the breadcrumb. The first result will be Users / {user} / Comments, and the second
will be Users / Comments.
Disabling Breadcrumbs
You can disable click events on certain breadcrumbs.
Note: This doesn't hide the link; it only disables the click event.
use BoredProgrammers\LaraBreadcrumb\Service\BreadcrumbService; // Route::get('/users/{user}/comments/{comment}'); $breadcrumbs = BreadcrumbService::update()->disable('comments'); $breadcrumbs = BreadcrumbService::update()->disable(['comments', 'users']);
After this, you won't be able to click on the comments breadcrumb in the first example and on the comments
and users breadcrumbs in the second example.
To disable dynamic segments, use curly braces {}:
use BoredProgrammers\LaraBreadcrumb\Service\BreadcrumbService; // Route::get('/users/{user}/comments/{comment}'); $breadcrumbs = BreadcrumbService::update()->disable('{comment}'); $breadcrumbs = BreadcrumbService::update()->disable(['{user}', '{comment}']);
After this, you won't be able to click on the comment breadcrumb in the first example and on the user and comment
breadcrumbs in the second example.
Translating Breadcrumbs
You can translate certain breadcrumbs or all breadcrumbs by default:
use BoredProgrammers\LaraBreadcrumb\Service\BreadcrumbService; // Translate certain segments BreadcrumbService::update()->translate('users'); BreadcrumbService::update()->translate(['users', 'comments']); // Translate all segments by default BreadcrumbService::update()->translateAll();
If you want to translate all breadcrumbs but don't want to translate certain segments, you can use the dontTranslate
method:
use BoredProgrammers\LaraBreadcrumb\Service\BreadcrumbService; BreadcrumbService::update()->translateAll(true); // Don't translate certain segments BreadcrumbService::update()->dontTranslate('users'); BreadcrumbService::update()->dontTranslate(['users', 'comments']);
This ensures that the 'users' segment isn't translated in the first example, and the 'users' and 'comments' segments aren't translated in the second example, even if translateAll is set to true.
If you want to translate dynamic segments, you must use curly braces {}.
use BoredProgrammers\LaraBreadcrumb\Service\BreadcrumbService; // Route::get('/users/{user}/comments/{comment}'); BreadcrumbService::update()->translate('{user}'); BreadcrumbService::update()->translate(['{user}', '{comment}']);
Publishing views
If you want to customize the views, you can publish them with this command:
php artisan vendor:publish --tag=larabreadcrumb-views
Contributing
We welcome contributions to LaraBreadcrumb. If you'd like to contribute, please fork the repository, make your changes, and submit a pull request. We have a few requirements for contributions:
- Follow the PSR-2 coding standard.
- Only use pull requests for contributions.
Changelog
For a detailed history of changes, see releases on GitHub.
License
This project is licensed under the MIT license.
Contact Information
For any questions or concerns, please feel free to create a discussion on GitHub.
Credits
Created by Matěj Černý from Bored Programmers.
Acknowledgments
We would like to thank all the contributors who have helped to make LaraBreadcrumb a better package.
bored-programmers/larabreadcrumb 适用场景与选型建议
bored-programmers/larabreadcrumb 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 33 次下载、GitHub Stars 达 2, 最近一次更新时间为 2023 年 12 月 24 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「breadcrumbs」 「navigation」 「laravel」 「Laravel Navigation」 「laravel breadcrumbs」 「breadcrumb generation」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 bored-programmers/larabreadcrumb 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 bored-programmers/larabreadcrumb 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 bored-programmers/larabreadcrumb 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Breadcrumbs integration for Laravel 6
A block to display a list of links to child pages, or pages in current level
Navigation bundle for Symfony applications
Laravel Menu management
Control pro Nette Framework usnadňující tvorbu menu a drobečkové navigace
Alfabank REST API integration
统计信息
- 总下载量: 33
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 16
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-12-24