dillingham / nova-ajax-select
Nova Ajax Select
1.0.4
2020-08-27 16:52 UTC
Requires
- php: >=7.1.0
README
基于其他字段的值以及它们发生变化时填充的Ajax选择字段。
安装
composer require dillingham/nova-ajax-select
使用方法
指定请求URL,并可选地指定要监视并触发Ajax选择的parent($attribute)
use NovaAjaxSelect\AjaxSelect;
BelongsTo::make('Company'), AjaxSelect::make('User') ->get('/api/company/{company}/users') ->parent('company'),
添加索引和详细视图显示的字段。AjaxSelect仅适用于表单
BelongsTo::make('User')->exceptOnForms(),
请求URL
在上面的示例中,我们说company
是父字段。
{company}
URL参数将与所选的Company
字段值相等。
响应格式
选择字段期望有value
和display
。将结果映射如下
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']);
使子项依赖于其他子项
City
根据State
进行请求,而State
则根据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'),
使多个子项依赖于一个父项
File
和Comment
都将根据Project
进行请求。
BelongsTo::make('Project'), AjaxSelect::make('File') ->get('/{project}/files') ->parent('project'), AjaxSelect::make('Comment') ->get('/{project}/comments') ->parent('project'),
作者
嗨 👋,我是Brian Dillingham,这是此Nova包的创建者以及其他包
希望你会觉得它有用。欢迎提供反馈。
在推特上关注我:@im_brian_d