Implementing Breadcrumbs in Laravel with laravel-breadcrumbs
Thank you for your continued support.
This article contains advertisements that help fund our operations.
Table Of Contents
Using the package called laravel-breadcrumbs, we will implement breadcrumbs in Laravel.
What are Breadcrumbs?
Breadcrumbs are designed to help users navigate a website easily by showing their current location, such as Home ➡ Category ➡ Product.
The origin of the name "breadcrumbs" comes from the story of Hansel and Gretel, where the siblings left breadcrumbs in the forest to find their way back.
Laravel provides a package that makes it relatively easy to create breadcrumbs, and I would like to explain how to use it in this article.
Check out the Table of Contents of Laravel articles here
Environment
MacOS Laravel6 "diglactic/laravel-breadcrumbs": "^6.1",
Installing the Breadcrumbs Package
composer require diglactic/laravel-breadcrumbs
Creating the Breadcrumbs Definition File
Create the file in the same folder as web.php or api.php.
routes/breadcrumbs.php
Add content like this:
<?php
// Home
Breadcrumbs::for('home', function ($trail) {
$trail->push('Home', route('home'));
});
The rest of the article has been translated into English.