PHP code example of formfeed-uk / nova-breadcrumbs
1. Go to this page and download the library: Download formfeed-uk/nova-breadcrumbs library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
formfeed-uk / nova-breadcrumbs example snippets
public function boot() {
parent::boot();
Nova::withBreadcrumbs(true);
}
class MyModel extends Model {
...
public function parent() {
return $this->config();
}
public function config() {
return $this->belongsTo(Config::class, "config_id");
}
...
}
class MyResource extends Resource {
// Change the name of the breadcrumb
public function detailBreadcrumb(NovaRequest $request, Breadcrumbs $breadcrumbs, Breadcrumb $detailBreadcrumb) {
return $detailBreadcrumb->name = _('My Custom Name');
}
// Remove all previous breadcrumbs and add a new root
public function resourceBreadcrumbs(NovaRequest $request, Breadcrumbs $breadcrumbs, array $breadcrumbArray) {
$breadcrumbs->items = [Breadcrumb::make('Home', '/')];
return $breadcrumbArray;
}
// Prevent the group breadcrumb for this resource
public function groupBreadcrumb(NovaRequest $request, Breadcrumbs $breadcrumbs, Breadcrumb $groupBreadcrumb) {
return null;
}
}
use FormFeed\Breadcrumbs\Breadcrumb;
use FormFeed\Breadcrumbs\Breadcrumbs;
class NovaServiceProvider extends ServiceProvider {
public function boot() {
parent::boot();
Nova::withBreadcrumbs(true);
Breadcrumbs::detailCallback(function(NovaRequest $request, Breadcrumbs $breadcrumbs, Breadcrumb $detailBreadcrumb) {
return $detailBreadcrumb->name = _('My Custom Name');
});
Breadcrumbs::rootCallback(function(NovaRequest $request, Breadcrumbs $breadcrumbs, Breadcrumb $rootBreadcrumb) {
return Breadcrumb::make(_('My Custom Root Breadcrumb'), "/my-root");
});
}
}