Git Product home page Git Product logo

Comments (4)

imevul avatar imevul commented on June 18, 2024

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.

d13r avatar d13r commented on June 18, 2024

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.

Andreyco avatar Andreyco commented on June 18, 2024

I think this is resolved here #24

from laravel-breadcrumbs.

d13r avatar d13r commented on June 18, 2024

Released in 2.2.0.

from laravel-breadcrumbs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.