All Projects → tabuna → Breadcrumbs

tabuna / Breadcrumbs

Licence: mit
Laravel Breadcrumbs - An easy way to add breadcrumbs to your @Laravel app.

Projects that are alternatives of or similar to Breadcrumbs

Laraplans
SaaS style recurring plans for Laravel.
Stars: ✭ 163 (-3.55%)
Mutual labels:  laravel
Laravel Rate Limited Job Middleware
A job middleware to rate limit jobs
Stars: ✭ 166 (-1.78%)
Mutual labels:  laravel
Phphub5
PHPHub Ver 5 is a Forum project Powered by Laravel 5.1, and it is also the project build up PHP & Laravel China community (此项目已弃用)
Stars: ✭ 1,971 (+1066.27%)
Mutual labels:  laravel
Argon
Argon Frontend Preset For Laravel Framework 8.x and Up
Stars: ✭ 165 (-2.37%)
Mutual labels:  laravel
Github Labels
Add github labels automatically
Stars: ✭ 165 (-2.37%)
Mutual labels:  laravel
Ignition Go
Bootstrap4 /Codeigniter 3 Modular (HMVC) App Building Framework - to build enterprise class web applications... Versions: CodeIgniter 3.1.9 AdminLTE 3.4 Bootstrap 4.5.0
Stars: ✭ 166 (-1.78%)
Mutual labels:  laravel
Laravel Location
A simple Laravel Package to sort Countries, States and Cities
Stars: ✭ 162 (-4.14%)
Mutual labels:  laravel
Laravel Google Captcha
Google captcha for Laravel 5, Laravel 6 and Laravel 7, support multiple captcha on page
Stars: ✭ 168 (-0.59%)
Mutual labels:  laravel
Livewire Alert
SweetAlert2 wrapper for Livewire
Stars: ✭ 161 (-4.73%)
Mutual labels:  laravel
Logviewer
📃 Provides a log viewer for Laravel
Stars: ✭ 2,098 (+1141.42%)
Mutual labels:  laravel
Microweber
Drag and Drop Website Builder and CMS with E-commerce
Stars: ✭ 2,226 (+1217.16%)
Mutual labels:  laravel
Laravel Page Speed
Package to optimize your site automatically which results in a 35%+ optimization
Stars: ✭ 2,097 (+1140.83%)
Mutual labels:  laravel
Awesome Opensource Apps
🏠ℹ️ Curated list of awesome open source crafted web & mobile applications - Learn, Fork, Contribute & Most Importantly Enjoy!
Stars: ✭ 2,199 (+1201.18%)
Mutual labels:  laravel
Support
💪 Support package is a collection of helpers and tools for ARCANEDEV + Laravel projects.
Stars: ✭ 164 (-2.96%)
Mutual labels:  laravel
Partyline
Output to Laravel's console from outside of your Command classes.
Stars: ✭ 168 (-0.59%)
Mutual labels:  laravel
Roastapp
Laravel学院 Roast 应用源码
Stars: ✭ 164 (-2.96%)
Mutual labels:  laravel
Laravel Realtime Example
Realtime 🍕 Pizza Order Tracker 🍕 - Laravel, Vue & Pusher
Stars: ✭ 165 (-2.37%)
Mutual labels:  laravel
Bugsnag Cocoa
Bugsnag crash reporting for iOS, macOS and tvOS apps
Stars: ✭ 167 (-1.18%)
Mutual labels:  breadcrumbs
Imall
基于Laravel5.2,Vue.js1.0的微信商城,用于熟悉 Laravel、Vuejs、Webpack、Gulp 的结合使用,已不维护及更新。(1MB单核基础服务器,浏览请耐心等待图片加载...)
Stars: ✭ 168 (-0.59%)
Mutual labels:  laravel
Themes
🎨 Laravel Themes package with support for the Caffeinated Modules package.
Stars: ✭ 167 (-1.18%)
Mutual labels:  laravel

Laravel Breadcrumbs

Tests codecov Total Downloads Latest Version on Packagist

Introduction

Breadcrumbs display a list of links indicating the position of the current page in the whole site hierarchy. For example, breadcrumbs like Home / Sample Post / Edit means the user is viewing an edit page for the "Sample Post." He can click on "Sample Post" to view that page or click on "Home" to return to the homepage.

Home / Sample Post / Edit

This package for the Laravel framework will make it easy to build breadcrumbs in your application.

Installation

Run this at the command line:

$ composer require tabuna/breadcrumbs

This will update composer.json and install the package into the vendor/ directory.

Define your breadcrumbs

Now you can define breadcrumbs directly in the route files:

use Tabuna\Breadcrumbs\Trail;

// Home
Route::get('/', fn () => view('home'))
    ->name('home')
    ->breadcrumbs(fn (Trail $trail) =>
        $trail->push('Home', route('home'))
);

// Home > About
Route::get('/about', fn () => view('home'))
    ->name('about')
    ->breadcrumbs(fn (Trail $trail) =>
        $trail->parent('home')->push('About', route('about'))
);

You can also get arguments from the request:

Route::get('/category/{category}', function (Category $category){
    //In this example, the category object is your Eloquent model.
    //code...
})
    ->name('category')
    ->breadcrumbs(fn (Trail $trail, Category $category) =>
        $trail->push($category->title, route('category', $category->id))
);

Like to use a separate route file?

You can do this simply by adding the desired file to the service provider

namespace App\Providers;

use Illuminate\Support\ServiceProvider;

class BreadcrumbsServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap the application events.
     *
     * @return void
     */
    public function boot()
    {
        require base_path('routes/breadcrumbs.php');
    }
}

Then it will be your special file in the route directory:

// routes/breadcrumbs.php


// Photos
Breadcrumbs::for('photo.index', fn (Trail $trail) =>
    $trail->parent('home')->push('Photos', route('photo.index'))
);

Route resource

When using resources, a whole group of routes is declared for which you must specify values manually

// routes/web.php

Route::resource('photos', 'PhotoController');

It’s better to specify this in service providers, since route files can be cached

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Tabuna\Breadcrumbs\Breadcrumbs;
use Tabuna\Breadcrumbs\Trail;

class BreadcrumbsServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        Breadcrumbs::for('photos.index', fn (Trail $trail) =>
             $trail->push('Photos', route('home'))
        );
        
        Breadcrumbs::for('photos.create', fn (Trail $trail) =>
            $trail
                ->parent('photos.index', route('photos.index'))
                ->push('Add new photo', route('home'))
        );
    }
}

Output the breadcrumbs use Blade Component

You can use the output component:

<ul>
    <x-tabuna-breadcrumbs/>
</ul>

To define classes of list items, you can specify:

<x-tabuna-breadcrumbs
  class="item"
  active="active"
/>

You can also pass parameters:

<x-tabuna-breadcrumbs
    parameters="['value 1', 'value 2', 'value 3']"
/>

And call named routes explicitly:

<x-tabuna-breadcrumbs
    route="static"
/>

Output the breadcrumbs use Blade view

In order to display breadcrumbs on the desired page, simply call:

@if(Breadcrumbs::has())
    @foreach (Breadcrumbs::current() as $crumbs)
        @if ($crumbs->url() && !$loop->last)
            <li class="breadcrumb-item">
                <a href="{{ $crumbs->url() }}">
                    {{ $crumbs->title() }}
                </a>
            </li>
        @else
            <li class="breadcrumb-item active">
                {{ $crumbs->title() }}
            </li>
        @endif
    @endforeach
@endif

And results in this output:

Home / About

Credits

For several years, I successfully used the Dave James Miller package to solve my problems, but he stopped developing and supporting it. After a long search for alternatives, I liked the Dwight Watson package, but the isolation of breadcrumbs from the announcement of the routes did not give me rest. That's why I created this package. It uses the code of both previous packages.

License

The MIT License (MIT). Please see License File for more information.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].