jameron/breadcrumbs

Breadcrumb builder for Laravel and PHP applications.
30
Install
composer require jameron/breadcrumbs
Latest Version:1.0.7
License:MIT
Last Updated:Sep 7, 2017
Links: GitHub  ·  Packagist
Maintainer: Jameron

Breadcrumb

I wrote this to use in Laravel applications, but kept it loosely coupled so it can be used in any PHP application. The example view file uses blade template syntax but can easily be translated to straight up php or other templating engine.

To use within Laravel:

To install run:

composer require jameron/breadcrumbs

Add to config/app.php

add the service provider:

'providers' => [
    // ...
    Jameron\Breadcrumb\Providers\BreadcrumbServiceProvider::class,
],

add the facade to the aliases:

'aliases' => [
    // ...
    'Breadcrumb' => Jameron\Breadcrumb\Breadcrumb::class,
],

In your controller:

use Breadcrumb;
use Illuminate\Http\Request;

class ResourceController extends Controller
{

    protected $home_route;

    public function __construct()
    {
        $this->home_route = ['title'=>'home','url'=>'/home'];
    }

    public function index(Request $request)
    {

        $breadcrumb = (new Breadcrumb($request->path(), $this->home_route))->build();

        return view('resource.index', compact('breadcrumb'));

    }
}

Include the view partial into your layout or view file where you want the breadcrumb to appear.

E.g. @include('partials.utils.breadcrumb', ['items' => $breadcrumb])

in your breadcrumb partial add the following:

<ol class="breadcrumb">
    @foreach($crumbs as $item)
        <li>@if(!$item['active'])<a href="{!! $item['url'] !!}"@if($item['active']) class="active"@endif>@endif{!! $item['title'] !!}@if(!$item['active'])</a>@endif</li>
    @endforeach
</ol>

License

This breadcrumb is open-sourced software licensed under the MIT license.

Related Packages

oriceon/toastr-5-laravel

Easy toastr notifications for Laravel 5

494,357 79
php-tmdb/laravel

Laravel Package for TMDB ( The Movie Database ) API. Provides easy access to the...

53,305 162
oriceon/oauth-5-laravel

OAuth Service Provider for Laravel 5

1,622,037 174
artdarek/oauth-4-laravel

OAuth Service Provider for Laravel 4

517,742 679
narutimateum/toastr-5.2-laravel

toastr.js for Laravel 5.2 easy notification like growl for example

37,567 13