Skip to content

This project will show you how to use Laravel Breadcrumbs quickly. It's made up of two part, a tutorial article, and a simple demo.

Notifications You must be signed in to change notification settings

CycloneAxe/est-breadcrumbs-demo

Repository files navigation

For Chinese

Description

davejamesmiller/laravel-breadcrumbs A simple Laravel-style way to create breadcrumbs in Laravel 5.

This project is a very simple demo to show you how to use Laravel Breadcrumbs quickly.

This project was created by The EST Group and PHPHub.

Screenshots

Run the demo

You can refer to this documentation to know how to run this demo.

The Tutorial

Table of contents

  1. Installation
  2. Define your breadcrumbs
  3. Choose a template
  4. Basic Usage

1. Installation

1). To get started with Breadcrumbs, add to your composer.json file as a dependency:

composer require davejamesmiller/laravel-breadcrumbs

2). Integration in Laravel

Add the service provider to providers:

'providers' => [
    // ...
    DaveJamesMiller\Breadcrumbs\ServiceProvider::class,
],

And add the facade to aliases:

'aliases' => [
    // ...
    'Breadcrumbs' => DaveJamesMiller\Breadcrumbs\Facade::class,
],

2. Define your breadcrumbs

Create a file called app/Http/breadcrumbs.php that looks like this:

<?php

// Home
Breadcrumbs::register('home', function($breadcrumbs)
{
    $breadcrumbs->push('Home', route('home'));
});

// Home > Blog
Breadcrumbs::register('blog', function($breadcrumbs)
{
    $breadcrumbs->parent('home');
    $breadcrumbs->push('Blog', route('blog'));
});

3. Choose a template

By default a Bootstrap-compatible ordered list will be rendered, so if you’re using Bootstrap 3 you can skip this step.

First initialise the config file by running this command:

$ php artisan vendor:publish

Then open config/breadcrumbs.php and edit this line:

'view' => 'breadcrumbs::bootstrap3',

The possible values are:

Bootstrap 3: breadcrumbs::bootstrap3

Bootstrap 2: breadcrumbs::bootstrap2

4. Basic Usage

1). Edit app/HTTP/routes.php, make sure each of your routes has a name ('as' parameter):

Route::get('home', [
   'as' => 'home',
   function () {
       return view('home');
   }
]);

Route::get('blog', [
   'as' => 'blog',
   function () {
       return view('home');
   }
]);

2). Add this line to your views:

{!! Breadcrumbs::render('blog'); !!}

3). Then you'll get something like this:

That's it! 🍻 🍻 🍻

You can refer to the documentation to learn more about Laravel Breadcrumbs.


欢迎关注 LaravelTips, 这是一个专注于为 Laravel 开发者服务, 致力于帮助开发者更好的掌握 Laravel 框架, 提升开发效率的微信公众号.

About

This project will show you how to use Laravel Breadcrumbs quickly. It's made up of two part, a tutorial article, and a simple demo.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages