laravel-nova-field-dynamic-select icon indicating copy to clipboard operation
laravel-nova-field-dynamic-select copied to clipboard

Error: Invalid argument supplied foreach()

Open ronnytorresmtz opened this issue 5 years ago • 1 comments

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

ronnytorresmtz avatar May 31 '19 23:05 ronnytorresmtz

It's likely that none of the if statements apply so it's not returning an array. What is the output of $values?

marcuschristiansen avatar Dec 05 '19 19:12 marcuschristiansen