Reusable sections

Hi, I was wondering how you usually create reusable parts for example e.g. infolists or forms? For example I create my own AddressEntry that I am using on multiple resources. The problem comes when I need to access the Address model.

This is my demo custom entry:
<?php

namespace App\Filament\Components\Infolists\Entries;

class AddressEntry
{
    public static function make(string $name = 'address'): Entry
    {
        return TextEntry::make($name)
            ->label(__('Address'))
            ->hintAction(
                Action::make('openMaps')
                    ->url(fn (Model $record) => match (true) {
                        $record instanceof User => 'https://google.com/maps/place/'.$record->address->street,
                        $record instanceof Client => 'https://google.com/maps/place/'.$record->user->address->street,
                        default => 'https://google.com/maps/place/'.$record->street,
                    })
                    ->openUrlInNewTab(),
            );
    }
}

Model in my closure in url method is taken from resource, when I use it on UserResource, it is User etc.
It kinda works, but I don't like this implementation. Do you know better way?
Was this page helpful?