FilamentF
Filament8mo ago
wdog

Custom Icons in Breadcrumbs

Hi!

Is It possibile to add an icon before each element of a custom breadcrumb?

I've made a custom ViewField in a form with a custom breadcrumb to easily navigate related resources

(customer->contracts->resources)

what I need is to add a custom icon for each resource

( icon_customer + customer-> icon_contract + contracts-> icon_resource + resources)
Solution
<?php

namespace App\Forms\Components;

use Illuminate\Support\Collection;
use Filament\Forms\Components\View;
use Filament\Forms\Components\Field;

class CustomBreadcrumbField extends Field
{
    protected string $view = 'forms.components.custom-breadcrumb-field';

    protected \Closure $getItemsUsing;



    public function items(\Closure $closure): static
    {
        $this->getItemsUsing = $closure;
        return $this;
    }

    public function getItems(): array
    {
        $items =  ($this->getItemsUsing)($this->getRecord());

        return  collect($items)->map(function ($item) {
            return array_merge([
                'label' => null,
                'sub-label' => null,
                'url' => null,
                'icon' => null,
            ], $item);
        })->toArray();
    }
}
Was this page helpful?