Comments (4)
I use this code, which works but probably isn't the best solution.
function has_breadcrumb($name = NULL) {
if ($name === NULL) {
$name = Route::currentRouteName();
}
$excluded = ['home']; //TODO Move to config.
if (in_array($name, $excluded)) {
return FALSE;
}
return in_array($name, Breadcrumbs::getRegistered());
}
/**
* Render the breadcrumb for a certain route. (If it has one.)
* @param string $name The route to display breadcrumbs for.
* @param array $routeParameters Any route parameters to use. For example, the selected category.
* @return string|NULL Returns the breadcrumb HTML if successful, otherwise NULL.
*/
function render_breadcrumb($name = NULL, $routeParameters = array()) {
if ($name === NULL) {
$name = Route::currentRouteName();
}
if (has_breadcrumb($name)) {
return Breadcrumbs::render($name, $routeParameters);
}
}
As you can see, it requires a small modification to the Breadcrumbs library; a way to get the currently added breadcrumbs. ($this->callbacks)
This only works for named routes though, and you have to send func_get_args()
as $routeParameters
to the view, which can be a bit of a hassle. The best thing would be if you could just call Breadcrumbs::render()
without any parameters and it would get the current route stuff automatically.
Edit: This doesn't actually work since the 2.x update.
from laravel-breadcrumbs.
Since 2.0 you probably need Breadcrumbs::renderArray($name, $routeParameters)
instead.
An alternative to has_breadcrumb()
would be to put a try/catch around the call to render()
, but I'll keep that in mind and perhaps add Breadcrumbs::exists()
or similar too.
from laravel-breadcrumbs.
I think this is resolved here #24
from laravel-breadcrumbs.
Released in 2.2.0.
from laravel-breadcrumbs.
Related Issues (20)
- Dynamic breadcrumb - Trying to get property of non-object HOT 1
- Error logging
- Feature Request: Be able to pass the register name to the call back function HOT 1
- After execute the publish command, the config file not appear HOT 1
- json-ld Unspecified Type HOT 2
- Error en Ubuntu HOT 2
- Same errors with $breadcrumbs HOT 2
- Generate breadcrumbs for tabbed content HOT 4
- Wrong Readme Method parameter reference
- Method for does not exist. HOT 2
- can't get post category HOT 12
- How to pass the value to the bread crumbs with my admin panel? HOT 1
- It would be nice if I could put icons like this: HOT 1
- Laravel 5.7 Released HOT 1
- Add Laravel 5.7 support HOT 1
- installed the package and got Class 'Breadcrumbs' not found error HOT 2
- Feature Request UIKit breadcrumbs HOT 6
- Does this package even works??? HOT 3
- "Home" breadcrumb shows up twice, unable to remove it HOT 3
- breadcrumb 4 levels HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from laravel-breadcrumbs.