Download the PHP package glhd/gretel without Composer
On this page you can find all versions of the php package glhd/gretel. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package gretel
Gretel
Laravel breadcrumbs right out of a fairy tale.
Gretel is a Laravel package for adding route-based breadcrumbs to your application.
- Defining Breadcrumbs
- Displaying Breadcrumbs
- Using Gretel With Your CSS Framework of Choice
- Using a Custom Template (while maintaining accessibility)
- Caching Breadcrumbs (required if using
route:cache
) - Handling Errors
- Integration With Third Party Packages (Inertia.js)
Installation
Usage
Defining Breadcrumbs
Gretel adds a new Route macro that you can use when defining your routes:
Single Breadcrumb
In the simplest case, chain the breadcrumb()
function onto your existing route to define a breadcrumb:
If you need to dynamically control the title, pass in a closure instead:
Nested Breadcrumb
Breadcrumbs aren't very useful unless you string them together. Gretel handles nested breadcrumbs by pointing to a previously-defined parent breadcrumb:
Here, you can see that our users.show
route references users.index
as its parent. This way, when you render
breadcrumbs for users.show
it will also show the breadcrumb for users.index
.
Gretel assumes that the parameters in nested routes can be safely used for their parent routes. In this example,
users.edit
will render the users.show
breadcrumb using the User
value that was resolved for the edit action.
In the vast majority of cases, this is exactly what you want. If not, you can override this behavior (see below).
Parent Shorthand
Often, a child route will reference a parent with the same name prefix. In our above example, users.show
references
users.index
and users.edit
references users.show
. In this case, you can use the parent shorthand:
This is particularly useful for large apps that have many deeply nested routes.
Shallow Nested Routes
If your nested routes do not contain the route parameters necessary for the parent route, you will need to provide the values to Gretel. You can do this using a third callback:
Resource Routes
You can also define breadcrumbs for resource controllers. The index()
, create()
,
show()
, and edit()
methods behave exactly like the regular breadcrumb helper except that
they automatically set up the parent for you if you don’t provide one.
If you prefer, you can also use an array syntax for simple resource routes:
Vendor Routes
Sometimes you want to register breadcrumbs for routes that are defined in 3rd-party packages.
In this case, you can use the Gretel
facade directly. The API is exactly the same as the
Route::breadcrumb()
method, except that you must pass the route name as the first parameter:
Displaying Breadcrumbs
You can display the breadcrumbs for the current route with the <x-breadcrumbs />
Blade component. The Blade component
accepts a few optional attributes:
Attribute | |
---|---|
framework |
Render to match a UI framework ("tailwind" by default) |
view |
Render a custom view (supersedes the framework attribute) |
jsonld |
Render as a JSON-LD <script> tag |
Supported Frameworks
Gretel supports most common CSS frameworks. We've taken the CSS framework's documented markup and
added additional aria-
tags where appropriate for better accessibility. Currently supported frameworks:
Tailwind use "tailwind"
(default)
Materialize use "materialize"
Bootstrap 5 use "bootstrap5"
Bulma use "bulma"
Semantic UI use "semantic-ui"
Primer use "primer"
Foundation 6 use "foundation6"
UIKit use "uikit"
Older Frameworks
Older versions of some frameworks are also available:
- Bootstrap 3 use
"bootstrap3"
- Bootstrap 4 use
"bootstrap4"
- Foundation 5 use
"foundation5"
You'll typically want to include the <x-breadcrumbs />
tag somewhere in your application layout
(maybe twice if you're using JSON-LD):
layouts/app.blade.php
:
Custom Breadcrumb View
You can render a custom view either by publishing the gretel.php
config file via
php artisan vendor:publish
or by passing a view
attribute to the Blade component:
Using Breadcrumbs in Some Other Way
If you need to use the breadcrumbs in some other way—maybe for rending via a client-side
framework that Gretel doesn’t already integrate with—you can always just get the current
breadcrumbs as a Collection
or array
off the route:
For example, our Inertia.js integration could easily be implemented as:
Accessibility
If you choose to render your own view, please be sure to follow the current WAI-ARIA accessibility best practices. Gretel provides some helpers to make this easier:
Caching Breadcrumbs
Because Gretel breadcrumbs are registered alongside your routes, you need to cache your breadcrumbs if you cache your routes. You can do so with the two commands:
Please note that you must cache your breadcrumbs before you cache your routes.
Handling Errors
Sometimes you'll mis-configure a breadcrumb or forget to define one. You can register handlers
on the Gretel
facade to handle these cases:
Integration With Third Party Packages
Gretel automatically shares your breadcrumbs with Inertia.js if you have that package installed. You don't need to do anything to enable this integration. (If you do not want this behavior for some reason, you can disable it by publishing the Gretel config.)
Your breadcrumbs will be available in your client code as breadcrumbs
and look something like:
You can then render the breadcrumbs in the client however you see fit. Be sure to review the custom breadcrumbs section for information about how to ensure that your client-side breadcrumbs are fully accessible.
All versions of gretel with dependencies
illuminate/routing Version ^8|^9|^10|^11|12.x-dev|dev-master
illuminate/view Version ^8|^9|^10|^11|12.x-dev|dev-master
laravel/serializable-closure Version ^1.0