2017 © Pedro Peláez
 

library breadcrumb

A simple breadcrumb generator for Laravel 4

image

mj/breadcrumb

A simple breadcrumb generator for Laravel 4

  • Monday, November 17, 2014
  • by mjanssen
  • Repository
  • 3 Watchers
  • 13 Stars
  • 3,477 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 7 Forks
  • 0 Open issues
  • 1 Versions
  • 1 % Grown

The README.md

Laravel 4 Breadcrumbs

** If you have problems running setSeperator (typo'd) after update, I changed the function name to setSeperator., (*1)

A small and easy customizable breadcrumb generator for Laravel 4., (*2)

edit the .json

Edit your .json file and add the following line to your "require", (*3)

"mj/breadcrumb": "dev-master", (*4)

After this run the composer update to update your framework and get the breadcrumb class loaded into your files., (*5)

Setup

Open app.php in your config folder, (*6)

  1. Add the line 'Mj\Breadcrumb\BreadcrumbServiceProvider' to the providers array., (*7)

  2. To make use of the Facade that comes with Laravel 4, make sure you register the alias in the file 'app/config/app.php'., (*8)

Like this: 'Breadcrumb' => 'Mj\Breadcrumb\Facades\breadcrumb', (*9)

Usage

To create breadcrumbs use the following code:, (*10)

Breadcrumb::addbreadcrumb('linkname', 'url');, (*11)

You can add multiple breadcrumbs by repeating the code above., (*12)

To set an seperator you can use:, (*13)

Breadcrumb::setSeparator('yourseperator'), (*14)

At last send your breadcrumbs to your template (or just generate them) with the following command:, (*15)

Breadcrumb::generate(), (*16)

Example

Note: Use real url's (like /this/page) and not Laravel's URL helper. Not setting a URL at all will also work., (*17)

//Controller

public function page()
{
  //Those are required to set some breadcrumbs first.
  Breadcrumb::addBreadcrumb('home', '/');
  Breadcrumb::addBreadcrumb('some page', '/some-page');
  Breadcrumb::addBreadcrumb('last piece'); //Does not need a url because it's the last breadcrumb segment

    Breadcrumb::setSeparator('/'); //Set some seperator you think is nicest (not required)

  $data = array(
      'breadcrumbs' => Breadcrumb::generate() //Breadcrumbs UL is generated and stored in an array.
  )

  //return the view with the $data array to use it in the view
  return View::make('some/page', $data);
}

//View

{{$breadcrumbs}} // -> UL with list-items with the links :)

The Versions

17/11 2014

dev-master

9999999-dev

A simple breadcrumb generator for Laravel 4

  Sources   Download

MIT

The Requires

 

by Marnix Janssen