Laravel Community Tools by Tighten
Laravel Nova icon Nova Packages

Readme

Child select field for Laravel Nova

This field allows you to dynamically fill options of the select based on value in parent select field.

Field is based on nova-ajax-select. But instead of providing api endpoint, you can fill options by a closure function.

Install

composer require alvinhu/nova-child-select

Usage

Class have 2 special methods on top of default Select from Laravel Nova. parent should be a select field or another child select this one depends on. options should be a callable. it will receive parent select field's value as first argument and should return an array to be shown on the child select field.

Example

use Alvinhu\ChildSelect\ChildSelect;

public function fields(Request $request)
    {
        return [

            ID::make()->sortable(),

            Select::make('Country')
                ->options(Country::all()->mapWithKeys(function ($country) {
                    return [$country->id => $country->name];
                }))
                ->rules('required'),

            ChildSelect::make('City')
                ->parent('country')
                ->options(function ($value) { 
                    City::whereCountry($value)->get()->mapWithKeys(function ($city) {
                        return [$city->id => $city->name];
                    });
                })
                ->rules('required'),
        ];
    }

Back to Top
Added 6 years ago
Last updated 6 Years Ago
Version 1.0.5
Composer
alvinhu/nova-child-select
GitHub stars 20
Packagist downloads 171,139

Favorites

19 users favorited

Rating

2.30
(out of 5)
★★★★★
★★★★
★★★
★★
3 ratings

Author

Brought to you by Tighten

Issues/Feature Requests Stats Package Ideas