masardee / nova-search-relations-recursive

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

Simple Usage

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

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

Nested Relationship

If you want to search through a nested relationship, you could put another $searchRelations array style as a child.

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

About

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


Languages

Language:PHP 100.0%