Laravel Nova icon Nova Packages
S

Searchable BelongsTo Filter

Readme

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

Reviews

Rated 5 stars out of 5

By Alessio Piccioli on November 13, 2021

Awsome! Is there also a version for many-to-many relationships?

Rated 5 stars out of 5

By Nattapong Mongkolnavin on December 5, 2020

Great job. But need a way to clear the filter. I have to click the resource link again to reload and clear the filter.

Rated 5 stars out of 5

By Yevhen Koriakin on February 13, 2020

Good job!

Back to Top
Added 5 years ago
Last updated 5 Months Ago
Version v2.0.3
Nova Version ^4.0
Composer
suenerds/nova-searchable-belongs-to-filter
GitHub stars 30
Packagist downloads 370,716

Favorites

25 users favorited

Rating

5.00
(out of 5)
★★★★★
★★★★
★★★
★★
10 ratings

Tags

Brought to you by Tighten

Issues/Feature Requests Stats Package Ideas