Add shared data to Infolist Livewire fields

I am using custom LiveWire components in my Infolist which look like so:

                        InfolistSection::make('RVO')
                            ->schema([
                                Livewire::make(Details::class),
                            ]),
                        InfolistSection::make('RVO Verblijfplaats(en)')
                            ->collapsible()
                            ->collapsed()
                            ->schema([
                                Livewire::make(Locations::class),
                            ]),


But both of those components are making an identical call in the mount() function like so:
    public function mount(): void
    {
        $data = (new Animal)->detail($this->record->country_code, $this->record->registration_number)->get();
        $this->locations = $data ? $data['locations'] : false;
    }

and
    public function mount(): void
    {
        $data = (new Animal)->detail($this->record->country_code, $this->record->registration_number)->get();
        $this->details = $data ? $data['details'] : false;
        $this->translate();
    }


So i wanted to create the variable $data in the infolist function but i am unable to access the resource here.
Wanted situation:

     public static function infolist(Infolist $infolist): Infolist
    {
        $data = (new Animal)->detail($resource->record->country_code, $resource->record->registration_number)->get();

        return $infolist
            ->schema([


And then i would call the Livewire components as followed:

                        InfolistSection::make('RVO')
                            ->schema([
                                Livewire::make(Details::class, ['data' => $data]),
                            ]),


All this would be to not call the same Animal function on one page (since this is an API call to a third party). How would i be able to create an $data variable like above to pass to multiple Livewire fields in my infolist?
Solution
    public static function infolist(Infolist $infolist): Infolist
    {
        $record = $infolist->getRecord();
Was this page helpful?