suenerds/nova-searchable-belongs-to-filter

Searchable Nova filter for belongsTo relationships.
706,760 29
Install
composer require suenerds/nova-searchable-belongs-to-filter
Latest Version:v2.0.3
PHP:>=8.0
License:MIT
Last Updated:Dec 17, 2024
Links: GitHub  ·  Packagist
Maintainer: suenerds

nova-searchable-belongs-to-filter

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

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')
    ];
}

Related Packages

sereny/nova-searchable-filter

Nova searchable filter for belongsTo relationships.

23,514 4
webard/nova-havingable

Havingable macro for Laravel Nova fields, allowing filtering of aggregated value...

3,128 0
ampeco/nova-date-range-filter

A Laravel Nova date range filter.

1,057,454 35
optimistdigital/nova-detached-filters

This Laravel Nova package allows you to detach filters from the filter dropdown

244,121 63
mahi/spatie-tags-nova-filter

A Laravel Nova filter for Spatie/Laravel-Tags.

15,878 3