PHP code example of act-training / laravel-breadcrumbs

1. Go to this page and download the library: Download act-training/laravel-breadcrumbs library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

act-training / laravel-breadcrumbs example snippets




use ActTraining\LaravelBreadcrumbs\Facades\Breadcrumbs;

// Dashboard
Breadcrumbs::define('dashboard', function ($trail) {
    $trail->push('Dashboard', route('dashboard'));
});

// Users Index
Breadcrumbs::define('users.index', function ($trail) {
    $trail->parent('dashboard');
    $trail->push('Users', route('users.index'));
});

// User Show
Breadcrumbs::define('users.show', function ($trail, $user) {
    $trail->parent('users.index');
    $trail->push($user->name, route('users.show', $user));
});

use ActTraining\LaravelBreadcrumbs\Facades\Breadcrumbs;

// Generate breadcrumbs for a specific route
$breadcrumbs = Breadcrumbs::generate('users.show', $user);

// Generate breadcrumbs from current route
$breadcrumbs = Breadcrumbs::generateFromRoute();

// Check if breadcrumb exists
if (Breadcrumbs::exists('users.show')) {
    // ...
}

return [
    // Path to breadcrumb definitions file (defaults to routes/breadcrumbs.php if null)
    'definitions_file' => base_path('routes/breadcrumbs.php'),

    // Default view for rendering breadcrumbs
    'view' => 'breadcrumbs::breadcrumbs',

    // Hide breadcrumbs when only one item exists
    'skip_single_item' => true,

    // Separator character between breadcrumb items
    'separator' => '/',

    // CSS classes for breadcrumb elements
    'classes' => [
        'wrapper' => 'breadcrumbs',
        'list' => 'breadcrumb-list',
        'item' => 'breadcrumb-item',
        'link' => 'breadcrumb-link',
        'active' => 'breadcrumb-active',
        'separator' => 'breadcrumb-separator',
    ],

    // The route name that represents home (e.g., 'dashboard', 'home', 'index')
    'home_route' => 'dashboard',

    // How to display the home breadcrumb: 'icon', 'text', or 'both'
    'home_display' => 'icon',

    // The FluxUI icon to use for home (e.g., 'house', 'home', 'squares-2x2')
    'home_icon' => 'house',
];

Breadcrumbs::define('admin.users.roles.edit', function ($trail, $user, $role) {
    $trail->parent('admin.users.show', $user);
    $trail->push('Edit Role: ' . $role->name, route('admin.users.roles.edit', [$user, $role]));
});

Breadcrumbs::define('posts.show', function ($trail, $post) {
    if ($post->category) {
        $trail->parent('categories.show', $post->category);
    } else {
        $trail->parent('posts.index');
    }

    $trail->push($post->title, route('posts.show', $post));
});

// Define your home breadcrumb (defaults to 'dashboard')
Breadcrumbs::define('dashboard', function ($trail) {
    $trail->push('Dashboard', route('dashboard'));
});

// config/breadcrumbs.php

// Change which route is considered "home"
'home_route' => 'home', // or 'dashboard', 'index', etc.

// Control the display style
'home_display' => 'icon',  // Options: 'icon', 'text', 'both'

// Change the icon used
'home_icon' => 'house',    // Options: 'house', 'home', 'squares-2x2', or any FluxUI icon
bash
php artisan vendor:publish --tag="breadcrumbs-config"
bash
php artisan vendor:publish --tag="breadcrumbs-views"
bash
php artisan vendor:publish --tag="breadcrumbs-views"