suenerds / nova-searchable-belongs-to-filter

Searchable Nova filter for belongsTo relationships.

Stars
1

nova-searchable-belongs-to-filter

Searchable Nova filter for belongsTo relationships.

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:

// app/Nova/User.php
public function filters(Request $request)
{
    return [
	(new NovaSearchableBelongsToFilter)
	    ->fieldAttribute('department')
	    ->filterBy('department_id')
    ];
}