A badge is a small label next to the item, such as a counter.
// Value and CSS class
$item->badge(5, 'bg-green');
// With a closure, for values that need services
$item->badge(function (Badge $badge, \App\Repositories\Orders $orders) {
$badge->setValue($orders->pending()->count());
$badge->setClass('bg-red');
});
A string is always used as the value, even when it is also the name of a PHP function ('count', 'date'...). Only closures are run as callbacks.
An append is an extra link at the right of the item, such as a create shortcut.
// Route name, icon and title
$item->append('admin.users.create', 'fa fa-plus', 'New user');
// With a closure
$item->append(function (Append $append) {
$append->route('admin.users.create');
$append->icon('fa fa-plus');
$append->name('New user');
});
| Append method | Description |
|---|---|
route(string $name, array $params = []) |
Link from a named route. |
url(string $url) |
Link from a URL. |
icon(string $class) |
Icon CSS class. |
name(string $name) |
Title (tooltip) of the link. |
Badges and appends support authorize() and authorizePermission() too.