Skip to content

This package allow you to include relationship columns into Laravel Nova search query.

License

Notifications You must be signed in to change notification settings

thisisablock/nova-search-relations

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Search relationships in Laravel Nova

This package allows you to include relationship columns into Laravel Nova search query.

Screenshot

screenshot of the search relations tool

Installation

composer require titasgailius/search-relations

Next, add Titasgailius\SearchRelations\SearchesRelations trait to your base resource class App\Nova\Resource

use Titasgailius\SearchRelations\SearchesRelations;

abstract class Resource extends NovaResource
{
    use SearchesRelations;

Usage

Simply add public static $searchRelations array to any of your Nova resources. This array accepts a relationship name as a key and an array of searchable columns as a value.

/**
 * The relationship columns that should be searched.
 *
 * @var array
 */
public static $searchRelations = [
    'user' => ['username', 'email'],
];

Global search

You may customize the rules of your searchable relationships for global search by defining the $globalSearchRelations property.

/**
 * The relationship columns that should be searched globally.
 *
 * @var array
 */
public static $globalSearchRelations = [
    'user' => ['email'],
];

You may disable the global search for relationships by defining the $globalSearchRelations property with an empty array.

/**
 * The relationship columns that should be searched globally.
 *
 * @var array
 */
public static $globalSearchRelations = [];

Alternatevily, you may disable the global search for relationships by setting the $searchRelationsGlobally property to false.

/**
 * Determine if relations should be searched globally.
 *
 * @var array
 */
public static $searchRelationsGlobally = false;

Nested relationships

You may search nested relationships using dot notation.

/**
 * The relationship columns that should be searched.
 *
 * @var array
 */
public static $searchRelations = [
    'user.country' => ['code'],
];

About

This package allow you to include relationship columns into Laravel Nova search query.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%