suenerds / nova-searchable-belongs-to-filter
Searchable Nova filter for belongsTo relationships.
Installs: 333 867
Dependents: 0
Suggesters: 0
Security: 0
Stars: 30
Watchers: 3
Forks: 8
Open Issues: 8
Requires
- php: >=8.0
- laravel/framework: ^9.0|^10.0
- laravel/nova: ^4.0
This package is auto-updated.
Last update: 2024-10-31 00:24:08 UTC
README
Searchable Nova filter for belongsTo relationships.
⚠️⚠️⚠️ Attention ⚠️⚠️⚠️
This package is not needed with Nova 4, you can achieve the same behaviour with:
BelongsTo::make('User') ->searchable() ->filterable(),
Demo
Prerequisites
This package assumes you have a text-search setup for your Eloquent models. See Laravel Scout.
Installation
composer require suenerds/nova-searchable-belongs-to-filter
Usage
For this example let's assume a user belongs to a department and a department has many users.
To make the relationship searchable via a filter, add this to the filters()
function of your Nova user resource:
By default the filter will display the name of the fieldAttribute
you passed on instantiation. You can customize the name by passing it as an argument to the filter's construct function, for example my-new-name
.
// app/Nova/User.php use Suenerds\NovaSearchableBelongsToFilter\NovaSearchableBelongsToFilter public function filters(Request $request) { return [ (new NovaSearchableBelongsToFilter('my-new-name')) ->fieldAttribute('department') ->filterBy('department_id') ]; }