Hi, I am working on a public livewire full page component. In this component I am trying to set radio values based on a function which calls an api with data from the form to retrieve the options
This function sets a public property called $transportOptions. Now I want to use these options inside a Radio input. I start with calling the setTransportOptions() on afterStateUpdated on the fields which need to recall the api.
Then inside of the Radio input i have the following:
Radio::make('transport_option')
->hintAction(
Action::make('Retrieve Possible Transport Options')
->action(function ($livewire) {
$this->setTransportOptions($livewire);
dd($this->transportOptions);
})
)
->options(array_column($this->transportOptions, 'label', 'value'))
This is the setTransportOptions function
public static function setTransportOptions(&$livewire)
{
...
foreach ($vehicles as $vehicle) {
... API CALL ...
$livewire->transportOptions[] = [
'label' => $vehicle->name,
'value' => $vehicle->id,
'vehicle_id' => $vehicle->id,
'price' => $price,
'co2' => $co2,
'distance' => $distance,
'details' => [
['label' => 'Distance', 'value' => number_format($distance, 1), 'unit' => 'km'],
['label' => 'CO₂', 'value' => number_format($co2, 1), 'unit' => 'g'],
['label' => 'Price', 'value' => number_format($price, 2), 'unit' => '€']
]
];
}