-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Laravel Nova v4 support #113
Comments
dependsOn is now built into nova 4 and you can do this. public function fields(NovaRequest $request)
{
return [
BelongsTo::make('Unternehmen', 'company', Company::class)
->filterable()
->sortable(),
BelongsTo::make('Bereich', 'department', Department::class)
->nullable()
->exceptOnForms()
->sortable(),
Select::make('Bereich', 'department_id')
->onlyOnForms()
->dependsOn('company', function(Select $field, NovaRequest $request, FormData $formData) {
$company = \App\Company::where('id', $formData->company ?? $this->company_id)->first();
$field->options($company?->departments()->pluck('name', 'id'));
})
->default($this->location?->id)
->nullable()
->onlyOnForms(),
BelongsTo::make('Niederlassung', 'location', Location::class)
->nullable()
->sortable()
->exceptOnForms()
->withoutTrashed(),
Select::make('Niederlassung', 'location_id')
->onlyOnForms()
->dependsOn('company', function(Select $field, NovaRequest $request, FormData $formData) {
$company = \App\Company::where('id', $formData->company ?? $this->company_id)->first();
$field->options($company?->locations()->pluck('name', 'id'));
})
->default($this->department?->id)
->nullable()
->onlyOnForms(),
];
} |
@orlyapps how about filterable with dependsOn? |
I found a repository that compacts this process: https://github.com/webparking/nova-belongs-to-dependency |
A better example (relatableQueryUsing): BelongsTo::make('Unternehmen', 'company', Company::class)->rules('required'),
BelongsTo::make('Bereich', 'department', Department::class)
->dependsOn(['company'], function (BelongsTo $field, NovaRequest $request, FormData $data) {
$field->relatableQueryUsing(function ($request, $query) use ($data) {
return $query->where('company_id', $data->company);
});
})
->nullable(),
BelongsTo::make('Niederlassung', 'location', Location::class)
->dependsOn(['company'], function (BelongsTo $field, NovaRequest $request, FormData $data) {
$field->relatableQueryUsing(function ($request, $query) use ($data) {
return $query->where('company_id', $data->company);
});
})
->nullable(),
BelongsTo::make('Standort', 'place', Place::class)
->dependsOn(['location'], function (BelongsTo $field, NovaRequest $request, FormData $data) {
$field->relatableQueryUsing(function ($request, $query) use ($data) {
return $query->where('location_id', $data->location);
});
})
->nullable(), |
When was |
Chiming in with a complete solution in Nova 4, very close to @orlyapps but I use |
No description provided.
The text was updated successfully, but these errors were encountered: