cheesegrits / filament-google-maps

Google Maps package for Filament PHP
212 stars 60 forks source link

Passing Data to Livewire Component on Marker Action #100

Closed kmaphane closed 2 months ago

kmaphane commented 2 months ago

Good day,

I am trying to do the following:

public function markerAction(): Action { return Action::make('markerAction') ->label('Water meter details') ->infolist([ Section::make([ Livewire::make(DynamicWaterOverview::class, ['model_id' => $this->model_id]), ]), Section::make([ Livewire::make(WaterMeterOverview::class), ]), Section::make([ Livewire::make(AllHourlyConsumption::class), ]), ]) ->record(function (array $arguments) { if (array_key_exists('model_id', $arguments)) { $this->model_id = $arguments['model_id']; }

            return array_key_exists('model_id', $arguments) ? WaterMeter::find($arguments['model_id']) : null;

        })
        ->modalWidth('5xl')
        ->modalSubmitAction(false);
}

My modelId is always null when in the receiving livewire component. Any help I can get will be appreciated.

kmaphane commented 2 months ago

Okay figured it out. Sorry.

public function markerAction(): Action { return Action::make('markerAction') ->label('Water meter details') ->infolist(function (array $arguments) { $modelId = array_key_exists('model_id', $arguments) ? $arguments['model_id'] : null;

            return [
                Section::make([
                    Livewire::make(DynamicWaterOverview::class, ['modelId' => $modelId]),
                ]),
                Section::make([
                    Livewire::make(WaterMeterOverview::class),
                ]),
                Section::make([
                    Livewire::make(AllHourlyConsumption::class),
                ]),
            ];
        })
        ->record(function (array $arguments) {
            return array_key_exists('model_id', $arguments) ? WaterMeter::find($arguments['model_id']) : null;
        })
        ->modalWidth('5xl')
        ->modalSubmitAction(false);
}