Breadcrumbs

Sebastian asked 4 years ago
How can we add our own breadcrumbs on custom pages (using our own routes/Controllers )
1 Answers
laraship Staff answered 4 years ago
Hello Sebastian, Under each module, there is a file under the routes folder called  [module-name]_breadcrumbs.php, for example, "messaging_breadcrumbs.php", under this file you define the structure of the breadcrumbs for this module, for example
<?php

//Discussion
Breadcrumbs::register('discussions', function ($breadcrumbs) {
$breadcrumbs->parent('dashboard');
$breadcrumbs->push(trans('Messaging::module.discussion.title'), url(config('messaging.models.discussion.resource_url')));
});

Breadcrumbs::register('discussion_create_edit', function ($breadcrumbs) {
$breadcrumbs->parent('discussions');
$breadcrumbs->push(view()->shared('title_singular'));
});

Breadcrumbs::register('discussion_show', function ($breadcrumbs) {
$breadcrumbs->parent('discussions');
$breadcrumbs->push(view()->shared('title_singular'));
});
  as you can see there is a discussions menu as a child for the dashboard and another two children for the discussion module, to render the create_ediit breadcrumb you have to add the following section in the template
@slot('breadcrumb')
{{ Breadcrumbs::render('discussion_create_edit') }}
@endslot
Sebastian Wong replied 4 years ago

How can I add breadcrumbs to a non module?

laraship Staff replied 4 years ago

Please provide full details so we can help

Sebastian Wong replied 4 years ago

I’ve added in a new controller and route in web.php

Where can I defined the breadcrumbs