Skip to content

A free open source IT asset/license management system

32.3 KB
Raw Blame
<?php

namespace App\Providers;

use App\Models\Accessory;
use App\Models\AccessoryCheckout;
use App\Models\Asset;
use App\Models\AssetModel;
use App\Models\Category;
use App\Models\Company;
use App\Models\Component;
use App\Models\Consumable;
use App\Models\CustomField;
use App\Models\CustomFieldset;
use App\Models\Department;
use App\Models\Depreciation;
use App\Models\Group;
use App\Models\License;
use App\Models\Location;
use App\Models\Maintenance;
use App\Models\Manufacturer;
use App\Models\PredefinedKit;
use App\Models\Statuslabel;
use App\Models\Supplier;
use App\Models\User;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\ServiceProvider;
use Tabuna\Breadcrumbs\Breadcrumbs;
use Tabuna\Breadcrumbs\Trail;

class BreadcrumbsServiceProvider extends ServiceProvider
{
    /**
     * Handles the resource routes for first-class objects
     *
     * @return void
     */
    public function boot()
    {

        // Default home
        Breadcrumbs::for('home', fn (Trail $trail) => $trail->push('<x-icon type="home" /><span class="sr-only">'.trans('general.dashboard').'</span>', route('home'))
        );

        /**
         * Asset Breadcrumbs
         */
        $statusType = request()->status_type;
        if (request()->is('hardware*') && is_string($statusType) && $statusType !== '') {
            Breadcrumbs::for('hardware.index', fn (Trail $trail) => $trail->parent('home', route('home'))
                ->push(trans('general.assets'), route('hardware.index'))
                ->push(trans('general.'.strtolower(e($statusType))), route('hardware.index', ['status_type' => $statusType]))
            );

        } elseif (request()->is('hardware*') && request()->boolean('past_eol')) {
            Breadcrumbs::for('hardware.index', fn (Trail $trail) => $trail->parent('home', route('home'))
                ->push(trans('general.assets'), route('hardware.index'))
                ->push(trans('general.past_eol'), route('hardware.index', ['past_eol' => 1]))
            );

        } else {
            Breadcrumbs::for('hardware.index', fn (Trail $trail) => $trail->parent('home', route('home'))
                ->push(trans('general.assets'), route('hardware.index'))
            );
        }

        Breadcrumbs::for('hardware.create', fn (Trail $trail) => $trail->parent('hardware.index', route('hardware.index'))
            ->push(trans('general.create'), route('hardware.create'))
        );

        Breadcrumbs::for('clone/hardware', fn (Trail $trail) => $trail->parent('hardware.index', route('hardware.index'))
            ->push(trans('admin/hardware/general.clone'), route('hardware.create'))
        );

        Breadcrumbs::for('hardware.show', fn (Trail $trail, Asset $asset) => $trail->parent('hardware.index', route('hardware.index'))
            ->push($asset->display_name, route('hardware.show', $asset))
        );

        Breadcrumbs::for('hardware.edit', fn (Trail $trail, Asset $asset) => $trail->parent('hardware.index', route('hardware.index'))
            ->push($asset->display_name, route('hardware.show', $asset))
            ->push(trans('general.update'))
        );

        /**
         * Asset Model Breadcrumbs
         */
        if ((request()->is('models*')) && (request()->status == 'deleted')) {
            Breadcrumbs::for('models.index', fn (Trail $trail) => $trail->parent('hardware.index', route('hardware.index'))
                ->push(trans('general.asset_models'), route('models.index'))
                ->push(trans('general.deleted_models'), route('models.index', ['status' => request()->status]))
            );
        } else {
            Breadcrumbs::for('models.index', fn (Trail $trail) => $trail->parent('hardware.index', route('hardware.index'))
                ->push(trans('general.asset_models'), route('models.index'))
            );
        }

        Breadcrumbs::for('models.create', fn (Trail $trail) => $trail->parent('models.index', route('models.index'))
            ->push(trans('general.create'), route('models.create'))
        );

        Breadcrumbs::for('models.show', fn (Trail $trail, AssetModel $model) => $trail->parent('models.index', route('models.index'))
            ->push($model->name, route('models.show', $model))
        );

        Breadcrumbs::for('models.edit', fn (Trail $trail, AssetModel $model) => $trail->parent('models.index', route('models.index'))
            ->push($model->display_name, route('models.show', $model))
            ->push(trans('general.update'))
        );

        /**
         * Accessories Breadcrumbs
         */
        $accessoriesStatus = request()->status;
        if (request()->is('accessories*') && in_array($accessoriesStatus, ['Archived', 'Deleted'], true)) {
            Breadcrumbs::for('accessories.index', fn (Trail $trail) => $trail->parent('home', route('home'))
                ->push(trans('general.accessories'), route('accessories.index'))
                ->push(trans('general.'.strtolower($accessoriesStatus)), route('accessories.index', ['status' => $accessoriesStatus]))
            );
        } else {
            Breadcrumbs::for('accessories.index', fn (Trail $trail) => $trail->parent('home', route('home'))
                ->push(trans('general.accessories'), route('accessories.index'))
            );
        }

        Breadcrumbs::for('accessories.create', fn (Trail $trail) => $trail->parent('accessories.index', route('accessories.index'))
            ->push(trans('general.create'), route('accessories.create'))
        );

        Breadcrumbs::for('accessories.show', function (Trail $trail, Accessory $accessory) {
            $trail->parent('accessories.index', route('accessories.index'));

            // Deleted takes precedence over archived - a soft-deleted
            // archived item lives in the Deleted bucket, not Archived.
            // Linking the segment back to the filtered index gives the
            // operator a way to pop back to peers in the same state.
            if ($accessory->deleted_at) {
                $trail->push(trans('general.deleted'), route('accessories.index', ['status' => 'Deleted']));
            } elseif ($accessory->archived) {
                $trail->push(trans('general.archived'), route('accessories.index', ['status' => 'Archived']));
            }

            $trail->push($accessory->name, route('accessories.show', $accessory));
        });

        // Parent through .show so the Archived/Deleted segment that
        // show injects carries forward to Edit without duplicating
        // the state-detection logic here.
        Breadcrumbs::for('accessories.edit', fn (Trail $trail, Accessory $accessory) => $trail->parent('accessories.show', $accessory)
            ->push(trans('general.update'))
        );

        Breadcrumbs::for('accessories.checkout.show', fn (Trail $trail, Accessory $accessory) => $trail->parent('accessories.show', $accessory)
            ->push(trans('general.checkout'))
        );

        Breadcrumbs::for('accessories.checkin.show', function (Trail $trail, int $accessoryID) {
            $checkout = AccessoryCheckout::find($accessoryID);
            $accessory = $checkout ? Accessory::find($checkout->accessory_id) : null;
            $trail->parent('accessories.index');
            if ($accessory) {
                $trail->push($accessory->name, route('accessories.show', $accessory));
            }
            $trail->push(trans('general.checkin'));
        });

        Breadcrumbs::for('clone/accessories', fn (Trail $trail, Accessory $accessory) => $trail->parent('accessories.show', $accessory)
            ->push(trans('general.clone'))
        );

        /**
         * Categories Breadcrumbs
         */
        Breadcrumbs::for('categories.index', fn (Trail $trail) => $trail->parent('home', route('home'))
            ->push(trans('general.categories'), route('categories.index'))
        );

        Breadcrumbs::for('categories.create', fn (Trail $trail) => $trail->parent('categories.index', route('categories.index'))
            ->push(trans('general.create'), route('categories.create'))
        );

        Breadcrumbs::for('categories.show', fn (Trail $trail, Category $category) => $trail->parent('categories.index', route('categories.index'))
            ->push($category->name, route('categories.show', $category))
        );

        Breadcrumbs::for('categories.edit', fn (Trail $trail, Category $category) => $trail->parent('categories.index', route('categories.index'))
            ->push($category->display_name, route('categories.show', $category))
            ->push(trans('general.update'))
        );

        /**
         * Company Breadcrumbs
         */
        Breadcrumbs::for('companies.index', fn (Trail $trail) => $trail->parent('home', route('home'))
            ->push(trans('general.companies'), route('companies.index'))
        );

        Breadcrumbs::for('companies.create', fn (Trail $trail) => $trail->parent('companies.index', route('companies.index'))
            ->push(trans('general.create'), route('companies.create'))
        );

        Breadcrumbs::for('companies.show', function (Trail $trail, Company $company) {
            $trail->parent('companies.index', route('companies.index'));
            $this->pushCompanyHierarchy($trail, $company);
        });

        Breadcrumbs::for('companies.edit', function (Trail $trail, Company $company) {
            $trail->parent('companies.index', route('companies.index'));
            $this->pushCompanyHierarchy($trail, $company);
            $trail->push(trans('general.update'));
        });

        /**
         * Components Breadcrumbs
         */
        $componentsStatus = request()->status;
        if (request()->is('components*') && in_array($componentsStatus, ['Archived', 'Deleted'], true)) {
            Breadcrumbs::for('components.index', fn (Trail $trail) => $trail->parent('home', route('home'))
                ->push(trans('general.components'), route('components.index'))
                ->push(trans('general.'.strtolower($componentsStatus)), route('components.index', ['status' => $componentsStatus]))
            );
        } else {
            Breadcrumbs::for('components.index', fn (Trail $trail) => $trail->parent('home', route('home'))
                ->push(trans('general.components'), route('components.index'))
            );
        }

        Breadcrumbs::for('components.create', fn (Trail $trail) => $trail->parent('components.index', route('components.index'))
            ->push(trans('general.create'), route('components.create'))
        );

        Breadcrumbs::for('components.show', function (Trail $trail, Component $component) {
            $trail->parent('components.index', route('components.index'));

            // Mirror accessories.show: inject an Archived/Deleted
            // segment driven by the item's own state so operators
            // viewing a non-live row can pop back to peers in the
            // same bucket. Deleted takes precedence.
            if ($component->deleted_at) {
                $trail->push(trans('general.deleted'), route('components.index', ['status' => 'Deleted']));
            } elseif ($component->archived) {
                $trail->push(trans('general.archived'), route('components.index', ['status' => 'Archived']));
            }

            $trail->push($component->name, route('components.show', $component));
        });

        Breadcrumbs::for('components.edit', fn (Trail $trail, Component $component) => $trail->parent('components.show', $component)
            ->push(trans('general.update'))
        );

        Breadcrumbs::for('components.clone.create', fn (Trail $trail, Component $component) => $trail->parent('components.index', route('components.index'))
            ->push($component->display_name, route('components.show', $component))
            ->push(trans('general.clone'), route('components.create'))
        );

        Breadcrumbs::for('components.checkout.show', function (Trail $trail, int $componentID) {
            $component = Component::find($componentID);
            $trail->parent('components.index');
            if ($component) {
                $trail->push($component->name, route('components.show', $component));
            }
            $trail->push(trans('general.checkout'));
        });

        Breadcrumbs::for('components.checkin.show', function (Trail $trail, int $componentAssetId) {
            $componentAsset = DB::table('components_assets')->find($componentAssetId);
            $component = $componentAsset ? Component::find($componentAsset->component_id) : null;
            $trail->parent('components.index');
            if ($component) {
                $trail->push($component->name, route('components.show', $component));
            }
            $trail->push(trans('general.checkin'));
        });

        /**
         * Consumables Breadcrumbs
         */
        $consumablesStatus = request()->status;
        if (request()->is('consumables*') && in_array($consumablesStatus, ['Archived', 'Deleted'], true)) {
            Breadcrumbs::for('consumables.index', fn (Trail $trail) => $trail->parent('home', route('home'))
                ->push(trans('general.consumables'), route('consumables.index'))
                ->push(trans('general.'.strtolower($consumablesStatus)), route('consumables.index', ['status' => $consumablesStatus]))
            );
        } else {
            Breadcrumbs::for('consumables.index', fn (Trail $trail) => $trail->parent('home', route('home'))
                ->push(trans('general.consumables'), route('consumables.index'))
            );
        }

        Breadcrumbs::for('consumables.create', fn (Trail $trail) => $trail->parent('consumables.index', route('consumables.index'))
            ->push(trans('general.create'), route('consumables.create'))
        );

        Breadcrumbs::for('consumables.show', function (Trail $trail, Consumable $consumable) {
            $trail->parent('consumables.index', route('consumables.index'));

            // Deleted takes precedence over archived - a soft-deleted
            // archived item lives in the Deleted bucket, not Archived.
            // Linking the segment back to the filtered index gives the
            // operator a way to pop back to peers in the same state.
            if ($consumable->deleted_at) {
                $trail->push(trans('general.deleted'), route('consumables.index', ['status' => 'Deleted']));
            } elseif ($consumable->archived) {
                $trail->push(trans('general.archived'), route('consumables.index', ['status' => 'Archived']));
            }

            $trail->push($consumable->name, route('consumables.show', $consumable));
        });

        Breadcrumbs::for('consumables.edit', fn (Trail $trail, Consumable $consumable) => $trail->parent('consumables.show', $consumable)
            ->push(trans('general.update'))
        );

        Breadcrumbs::for('consumables.checkout.show', function (Trail $trail, $consumablesID) {
            $consumable = Consumable::find($consumablesID);
            $trail->parent('consumables.index');
            if ($consumable) {
                $trail->push($consumable->name, route('consumables.show', $consumable));
            }
            $trail->push(trans('general.checkout'));
        });

        Breadcrumbs::for('consumables.clone.create', fn (Trail $trail, Consumable $consumable) => $trail->parent('consumables.show', $consumable)
            ->push(trans('general.clone'))
        );

        /**
         * Custom fields Breadcrumbs
         */
        Breadcrumbs::for('fields.index', fn (Trail $trail) => $trail->parent('models.index', route('models.index'))
            ->push(trans('admin/custom_fields/general.custom_fields'), route('fields.index'))
        );

        Breadcrumbs::for('fields.create', fn (Trail $trail) => $trail->parent('fields.index', route('fields.index'))
            ->push(trans('general.create'), route('fields.create'))
        );

        Breadcrumbs::for('fields.edit', fn (Trail $trail, CustomField $field) => $trail->parent('fields.index', route('fields.index'))
            ->push(trans('general.update')) // We skip the show section here since there isn't really a concept of fields.show
        );

        /**
         * Custom fieldsets Breadcrumbs
         */
        Breadcrumbs::for('fieldsets.create', fn (Trail $trail) => $trail->parent('fields.index', route('fields.index'))
            ->push(trans('admin/custom_fields/general.create_fieldset'), route('fieldsets.create'))
        );

        Breadcrumbs::for('fieldsets.show', fn (Trail $trail, CustomFieldset $fieldset) => $trail->parent('fields.index', route('fields.index'))
            ->push($fieldset->name, route('fields.index'))
        );

        Breadcrumbs::for('fieldsets.edit', fn (Trail $trail, CustomFieldset $fieldset) => $trail->parent('fields.index', route('fields.index'))
            ->push($fieldset->display_name, route('fieldsets.show', $fieldset))
            ->push(trans('general.update'))
        );

        /**
         * Department Breadcrumbs
         */
        Breadcrumbs::for('departments.index', fn (Trail $trail) => $trail->parent('home', route('home'))
            ->push(trans('general.departments'), route('departments.index'))
        );

        Breadcrumbs::for('departments.create', fn (Trail $trail) => $trail->parent('departments.index', route('departments.index'))
            ->push(trans('general.create'), route('departments.create'))
        );

        Breadcrumbs::for('departments.show', fn (Trail $trail, Department $department) => $trail->parent('departments.index', route('departments.index'))
            ->push($department->name, route('home'))
        );

        Breadcrumbs::for('departments.edit', fn (Trail $trail, Department $department) => $trail->parent('departments.index', route('departments.index'))
            ->push($department->display_name, route('departments.show', $department))
            ->push(trans('general.update'))
        );

        /**
         * Department Breadcrumbs
         */
        Breadcrumbs::for('depreciations.index', fn (Trail $trail) => $trail->parent('home', route('home'))
            ->push(trans('general.depreciations'), route('depreciations.index'))
        );

        Breadcrumbs::for('depreciations.create', fn (Trail $trail) => $trail->parent('depreciations.index', route('depreciations.index'))
            ->push(trans('general.create'), route('depreciations.create'))
        );

        Breadcrumbs::for('depreciations.show', fn (Trail $trail, Depreciation $depreciation) => $trail->parent('depreciations.index', route('depreciations.index'))
            ->push($depreciation->name, route('depreciations.show', $depreciation))
        );

        Breadcrumbs::for('depreciations.edit', fn (Trail $trail, Depreciation $depreciation) => $trail->parent('depreciations.index', route('depreciations.index'))
            ->push($depreciation->display_name, route('depreciations.show', $depreciation))
            ->push(trans('general.update'))
        );

        /**
         * Groups Breadcrumbs
         */
        Breadcrumbs::for('groups.index', fn (Trail $trail) => $trail->parent('settings.index', route('settings.index'))
            ->push(trans('general.groups'), route('groups.index'))
        );

        Breadcrumbs::for('groups.create', fn (Trail $trail) => $trail->parent('groups.index', route('groups.index'))
            ->push(trans('general.create'), route('groups.create'))
        );

        Breadcrumbs::for('groups.show', fn (Trail $trail, Group $group) => $trail->parent('groups.index', route('groups.index'))
            ->push($group->name, route('groups.show', $group))
        );

        Breadcrumbs::for('groups.edit', fn (Trail $trail, Group $group) => $trail->parent('groups.index', route('groups.index'))
            ->push($group->display_name, route('groups.show', $group))
            ->push(trans('general.update'))
        );

        /**
         * Licenses Breadcrumbs
         */
        if ((request()->is('licenses*')) && (request()->status == 'inactive')) {
            Breadcrumbs::for('licenses.index', fn (Trail $trail) => $trail->parent('home', route('home'))
                ->push(trans('general.licenses'), route('licenses.index'))
                ->push(trans('general.show_inactive'), route('licenses.index'))
            );
        } elseif ((request()->is('licenses*')) && (request()->status == 'expiring')) {
            Breadcrumbs::for('licenses.index', fn (Trail $trail) => $trail->parent('home', route('home'))
                ->push(trans('general.licenses'), route('licenses.index'))
                ->push(trans('general.show_expiring'), route('licenses.index'))
            );
        } else {
            Breadcrumbs::for('licenses.index', fn (Trail $trail) => $trail->parent('home', route('home'))
                ->push(trans('general.licenses'), route('licenses.index'))
            );
        }

        Breadcrumbs::for('licenses.create', fn (Trail $trail) => $trail->parent('licenses.index', route('licenses.index'))
            ->push(trans('general.create'), route('licenses.create'))
        );

        Breadcrumbs::for('licenses.show', function (Trail $trail, License $license) {
            $trail->parent('licenses.index', route('licenses.index'));

            // Licenses don't support archived - soft-delete only - so
            // the inserted segment is just Deleted when applicable.
            if ($license->deleted_at) {
                $trail->push(trans('general.deleted'), route('licenses.index', ['status' => 'Deleted']));
            }

            $trail->push($license->name, route('licenses.show', $license));
        });

        Breadcrumbs::for('licenses.edit', fn (Trail $trail, License $license) => $trail->parent('licenses.show', $license)
            ->push(trans('general.update'))
        );

        /**
         * Locations Breadcrumbs
         */
        Breadcrumbs::for('locations.index', fn (Trail $trail) => $trail->parent('home', route('home'))
            ->push(trans('general.locations'), route('locations.index'))
        );

        Breadcrumbs::for('locations.create', fn (Trail $trail) => $trail->parent('locations.index', route('locations.index'))
            ->push(trans('general.create'), route('locations.create'))
        );

        Breadcrumbs::for('clone/location', fn (Trail $trail) => $trail->parent('locations.index', route('locations.index'))
            ->push(trans('admin/locations/table.clone'), route('locations.create'))
        );

        Breadcrumbs::for('locations.show', function (Trail $trail, Location $location) {
            $trail->parent('locations.index', route('locations.index'));
            $this->pushLocationHierarchy($trail, $location);
        });

        Breadcrumbs::for('locations.edit', function (Trail $trail, Location $location) {
            $trail->parent('locations.index', route('locations.index'));
            $this->pushLocationHierarchy($trail, $location);
            $trail->push(trans('general.update'));
        });

        /**
         * Maintenances Breadcrumbs
         */
        Breadcrumbs::for('maintenances.index', function (Trail $trail) {
            $trail->parent('hardware.index', route('hardware.index'))
                ->push(trans('general.maintenances'), route('maintenances.index'));

            if (request()->input('upcoming_status') === 'due') {
                $trail->push(trans('admin/maintenances/general.due'));
            } elseif (request()->input('upcoming_status') === 'overdue') {
                $trail->push(trans('admin/maintenances/general.overdue'));
            } elseif (request()->input('completed') === 'true') {
                $trail->push(trans('admin/maintenances/general.completed'));
            }
        });

        Breadcrumbs::for('maintenances.create', fn (Trail $trail) => $trail->parent('maintenances.index', route('maintenances.index'))
            ->push(trans('general.create'), route('maintenances.create'))
        );

        Breadcrumbs::for('maintenances.show', fn (Trail $trail, Maintenance $maintenance) => $trail->parent('maintenances.index', route('maintenances.index'))
            ->push($maintenance->name, route('maintenances.show', $maintenance))
        );

        Breadcrumbs::for('maintenances.edit', fn (Trail $trail, Maintenance $maintenance) => $trail->parent('maintenances.index', route('maintenances.index'))
            ->push($maintenance->display_name, route('maintenances.show', $maintenance))
            ->push(trans('general.update'))
        );

        /**
         * Manufacturers Breadcrumbs
         */
        Breadcrumbs::for('manufacturers.index', fn (Trail $trail) => $trail->parent('home', route('home'))
            ->push(trans('general.manufacturers'), route('manufacturers.index'))
        );

        Breadcrumbs::for('manufacturers.create', fn (Trail $trail) => $trail->parent('manufacturers.index', route('manufacturers.index'))
            ->push(trans('general.create'), route('manufacturers.create'))
        );

        Breadcrumbs::for('manufacturers.show', fn (Trail $trail, Manufacturer $manufacturer) => $trail->parent('manufacturers.index', route('manufacturers.index'))
            ->push($manufacturer->name, route('home'))
        );

        Breadcrumbs::for('manufacturers.edit', fn (Trail $trail, Manufacturer $manufacturer) => $trail->parent('manufacturers.index', route('manufacturers.index'))
            ->push($manufacturer->name, route('manufacturers.show', $manufacturer))
            ->push(trans('general.update'))
        );

        /**
         * Predefined Kits Breadcrumbs
         */
        Breadcrumbs::for('kits.index', fn (Trail $trail) => $trail->parent('home', route('home'))
            ->push(trans('general.kits'), route('kits.index'))
        );

        Breadcrumbs::for('kits.create', fn (Trail $trail) => $trail->parent('kits.index', route('kits.index'))
            ->push(trans('general.create'), route('kits.create'))
        );

        Breadcrumbs::for('kits.show', fn (Trail $trail, PredefinedKit $kit) => $trail->parent('kits.index', route('kits.index'))
            ->push($kit->name, route('kits.show', $kit))
        );

        Breadcrumbs::for('kits.edit', fn (Trail $trail, PredefinedKit $kit) => $trail->parent('kits.index', route('kits.index'))
            ->push($kit->display_name, route('kits.show', $kit))
            ->push(trans('general.update'))
        );

        /**
         * Status Labels Breadcrumbs
         */
        Breadcrumbs::for('statuslabels.index', fn (Trail $trail) => $trail->parent('home', route('home'))
            ->push(trans('general.status_labels'), route('statuslabels.index'))
        );

        Breadcrumbs::for('statuslabels.create', fn (Trail $trail) => $trail->parent('statuslabels.index', route('statuslabels.index'))
            ->push(trans('general.create'), route('statuslabels.create'))
        );

        Breadcrumbs::for('statuslabels.show', fn (Trail $trail, Statuslabel $statuslabel) => $trail->parent('statuslabels.index', route('statuslabels.index'))
            ->push($statuslabel->name, route('statuslabels.show', $statuslabel))
        );

        Breadcrumbs::for('statuslabels.edit', fn (Trail $trail, Statuslabel $statuslabel) => $trail->parent('statuslabels.index', route('statuslabels.index'))
            ->push($statuslabel->display_name, route('statuslabels.show', $statuslabel))
            ->push(trans('general.update'))
        );

        /**
         * Settings Breadcrumbs
         */
        Breadcrumbs::for('settings.index', fn (Trail $trail) => $trail->parent('home', route('home'))
            ->push(trans('general.admin'), route('settings.index'))
        );

        /**
         * Suppliers Breadcrumbs
         */
        Breadcrumbs::for('suppliers.index', fn (Trail $trail) => $trail->parent('home', route('home'))
            ->push(trans('general.suppliers'), route('suppliers.index'))
        );

        Breadcrumbs::for('suppliers.create', fn (Trail $trail) => $trail->parent('suppliers.index', route('suppliers.index'))
            ->push(trans('general.create'), route('suppliers.create'))
        );

        Breadcrumbs::for('suppliers.show', fn (Trail $trail, Supplier $supplier) => $trail->parent('suppliers.index', route('suppliers.index'))
            ->push($supplier->name, route('home'))
        );

        Breadcrumbs::for('suppliers.edit', fn (Trail $trail, Supplier $supplier) => $trail->parent('suppliers.index', route('suppliers.index'))
            ->push($supplier->display_name, route('suppliers.show', $supplier))
            ->push(trans('general.update'))
        );

        /**
         * Users Breadcrumbs
         */
        if ((request()->is('users*')) && (request()->status == 'deleted')) {
            Breadcrumbs::for('users.index', fn (Trail $trail) => $trail->parent('home', route('home'))
                ->push(trans('general.users'), route('users.index'))
                ->push(trans('general.deleted_users'), route('users.index'))
            );
        } elseif ((request()->is('users*')) && (request()->admins == 'true')) {
            Breadcrumbs::for('users.index', fn (Trail $trail) => $trail->parent('home', route('home'))
                ->push(trans('general.users'), route('users.index'))
                ->push(trans('general.show_admins'), route('users.index'))
            );
        } elseif ((request()->is('users*')) && (request()->superadmins == 'true')) {
            Breadcrumbs::for('users.index', fn (Trail $trail) => $trail->parent('home', route('home'))
                ->push(trans('general.users'), route('users.index'))
                ->push(trans('general.show_superadmins'), route('users.index'))
            );
        } elseif ((request()->is('users*')) && (request()->activated == '0')) {
            Breadcrumbs::for('users.index', fn (Trail $trail) => $trail->parent('home', route('home'))
                ->push(trans('general.users'), route('users.index'))
                ->push(trans('general.login_disabled'), route('users.index'))
            );
        } elseif ((request()->is('users*')) && (request()->activated == '1')) {
            Breadcrumbs::for('users.index', fn (Trail $trail) => $trail->parent('home', route('home'))
                ->push(trans('general.users'), route('users.index'))
                ->push(trans('general.login_enabled'), route('users.index'))
            );
        } elseif ((request()->is('users*')) && request()->filled('end_date_within')) {
            Breadcrumbs::for('users.index', fn (Trail $trail) => $trail->parent('home', route('home'))
                ->push(trans('general.users'), route('users.index'))
                ->push(trans('general.offboarding_soon'), route('users.index'))
            );
        } else {
            Breadcrumbs::for('users.index', fn (Trail $trail) => $trail->parent('home', route('home'))
                ->push(trans('general.users'), route('users.index'))
            );
        }

        Breadcrumbs::for('users.create', fn (Trail $trail) => $trail->parent('users.index', route('users.index'))
            ->push(trans('general.create'), route('users.create'))
        );

        Breadcrumbs::for('users.clone.show', fn (Trail $trail) => $trail->parent('users.index', route('users.index'))
            ->push(trans('admin/users/general.clone'), route('users.create'))
        );

        Breadcrumbs::for('users.show', fn (Trail $trail, User $user) => $trail->parent('users.index', route('users.index'))
            ->push($user->display_name ?? 'Missing Username!', route('users.show', $user))
        );

        Breadcrumbs::for('users.edit', fn (Trail $trail, User $user) => $trail->parent('users.index', route('users.index'))
            ->push($user->display_name, route('users.show', $user))
            ->push(trans('general.update'))
        );

    }

    /**
     * Append parent -> child location breadcrumbs recursively for a location.
     */
    private function pushLocationHierarchy(Trail $trail, Location $location): void
    {
        $ancestorChain = [];
        $cursor = $location;

        while ($cursor !== null) {
            array_unshift($ancestorChain, $cursor);
            $cursor = $cursor->parent;
        }

        foreach ($ancestorChain as $node) {
            $trail->push($node->name, route('locations.show', $node));
        }
    }

    /**
     * Append parent -> child breadcrumbs for a company. The one-level-deep
     * validator on parent_id caps the chain at depth 2, so this is always
     * either [company] or [parent, company].
     */
    private function pushCompanyHierarchy(Trail $trail, Company $company): void
    {
        if ($company->parent) {
            $trail->push($company->parent->name, route('companies.show', $company->parent));
        }

        $trail->push($company->display_name, route('companies.show', $company));
    }
}