4

I have a select field in my resource that looks like this:

Select::make('Category', 'category')->options([
    'local' => 'Local',
    'ftp' => 'FTP',
]),

Now I want to display an other field based on the value a user selects in the Category field.

I use this package for conditional fields: https://github.com/epartment/nova-dependency-container

And this package for json schema's: https://github.com/NikolaySav/nova-json-schema-field

My goals is to display a different json schema for the user to fill in based on the category they have selected.

This is my code:

NovaDependencyContainer::make([
            NovaJsonSchemaField::make('Properties', $this->schema($category))
                ->listClass('list-reset'),
])->dependsOnNotEmpty('category'),

private function schema($category): array
{
    $allSchemas = [
                    'ftp' => [
                        'type' => 'object',
                        'required' => [
                            'foo',
                            'bar',
                        ],
                        'properties' => [
                            'foo' => [
                                'type' => 'string',
                            ],
                            'bar' => [
                                'type' => 'string',
                            ],
                        ],
                    ],
                ];

    return $allSchemas[$category];
}

But I don't know how I can fill up my $category variable with the selected category. The $category variable should be my selected value from the select.

I don't find any information on this in the Nova documentation.

michael
  • 421
  • 6
  • 21

0 Answers0