sanderbaas / laravel-nova-belongsto-dependency
Extend Laravel Nova so that searchable BelongsTo fields can be filtered by values of other fields
Installs: 3 748
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 1
Open Issues: 3
Language:JavaScript
Requires
- php: >=7.1.0
This package is auto-updated.
Last update: 2020-12-26 18:28:31 UTC
README
This package adds extra parameters to the request used by the BelongsTo fields to fetch the options. The extra parameters are the selected values of other fields so they can be used to filter the options based on selections in other fields. The extra parameters are only passed when using a BelongsTo field that is searchable.
Installation
You can install this package on a Laravel app that uses Nova via composer:
composer require sanderbaas/laravel-nova-belongsto-dependency
Usage
Make sure the fields of which the values should be filtered based on selections
of other fields are ->searchable()
.
return [ ... BelongsTo::make('Company'), BelongsTo::make('Employee') ->searchable(), ... ];
Then on the Employee resource, in this case, use the extra fields to filter the correct employees as follows:
public static function relatableQuery(NovaRequest $request, $query) { $query->where('company_id', '=', $request->selectedCompany); return $query; }
Credits
I got the idea of adding selected values to the request from experience with Backpack for Laravel. Also I was inspired by the package of manmohanjit: nova-belongsto-dependency
License
The MIT License (MIT). Please see License File for more information.