alexwenzel/ajax-select

A Laravel Nova 4 field - Ajax Select
79,673 2
Install
composer require alexwenzel/ajax-select
Latest Version:1.1
PHP:^8.0
License:MIT
Last Updated:Mar 25, 2025
Links: GitHub  ·  Packagist
Maintainer: alexwenzel

Nova Ajax Select (Nova 4)

Ajax populated select fields based on the values of other fields and when they change.

This is a fork of https://github.com/dillingham/nova-ajax-select and only supports nova 4 and php 8.

nova-ajax-select

Install

composer require alexwenzel/ajax-select

Usage

Specify a request url & optionally the parent($attribute) to watch & trigger the ajax select:

use Alexwenzel\AjaxSelect\AjaxSelect;
BelongsTo::make('Company'),

AjaxSelect::make('User')
    ->get('/api/company/{company}/users')
    ->parent('company'),

Add the field for index & detail views display. AjaxSelect is for forms only

BelongsTo::make('User')->exceptOnForms(),

Request Url:

In the above example, we say company is the parent.

The {company} url parameter will equal the selected Company field value.

Response Format:

The select field expects a value & display. Map your results like so:

Route::get('api/company/{company}/users', function($company_id) {

    $company = \App\Company::find($company_id);

    return $company->users->map(function($user) {
        return [ 'value' => $user->id, 'display' => $user->name ];
    });
})->middleware(['nova']);

Make children depend on other children

City makes a request based on State, which makes a request based on Country:

Select::make('Country')
    ->options([]),

AjaxSelect::make('State')
    ->get('/api/country/{country}/states')
    ->parent('country'),

AjaxSelect::make('City')
    ->get('/api/state/{state}/cities')
    ->parent('state'),

Make multiple children depend on one parent

File & Comment will both make a request based on Project

BelongsTo::make('Project'),

AjaxSelect::make('File')
    ->get('/{project}/files')
    ->parent('project'),

AjaxSelect::make('Comment')
    ->get('/{project}/comments')
    ->parent('project'),

Related Packages

ziffmedia/nova-select-plus

A Nova select field for simple and complex select inputs

656,394 95
outl1ne/nova-multiselect-field

A multiple select field for Laravel Nova.

3,938,567 343
optimistdigital/nova-multiselect-field

A multiple select field for Laravel Nova.

3,823,516 343
lrgt/laravel-form-ajax-validation

Make ajax validation with Laravel Requests for forms with bootstrap

5,768 43
laravel-enso/select

Bootstrap Select data builder with server-side data fetching capability and a Vu...

62,546 26

Version History

Version Released PHP Laravel License
1.1 ^8.0 ^8.0|^9.0|^10.0|^11.0|^12.0 MIT
1.0 ^8.0 MIT