Skip to content

stefblokdijk/nova-searchable-belongs-to-filter

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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:

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

About

Searchable Nova filter for belongsTo relationships

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Vue 49.2%
  • PHP 30.4%
  • JavaScript 20.2%
  • SCSS 0.2%