laravel-nova-field-dynamic-select
laravel-nova-field-dynamic-select copied to clipboard
Error: Invalid argument supplied foreach()
I am getting this error:
Invalid argument supplied foreach()
My code is
DynamicSelect::make(__('Rate by'))->options([
'Weight' => 'Weight',
'Trip' => 'Trip',
'Distance' => 'Distance',
])
->rules('required'),
DynamicSelect::make(__('UnitOfMeasure'))
->dependsOn(['Rate by']) <==I tested as array and as string
->options(function($values) {
if ($values['Rate by'] === 'Weight') {
return ['Tons' => 'Tons', 'Kgs' => 'Kgs'];
}
if ($values['Rate by'] === 'Trip') {
return ['Trip' => 'Trip'];
}
if ($values['Rate by'] === 'Distance') {
return ['Miles' => 'Miles', 'Kms' => 'Kms'];
}
})
->rules('required'),
Do I missing something?
I appreciate any help
It's likely that none of the if statements apply so it's not returning an array. What is the output of $values?