shepp/nova-concat-search

Search by Concatenated fields in Laravel Nova

v1.0.0 2022-09-27 13:16 UTC

This package is auto-updated.

Last update: 2025-06-27 19:44:29 UTC


README

Allows searching for Resources by a concatenation of multiple fields in Laravel Nova.

Example

An example use case is where a table contains first_name and last_name, and the Nova user would like to search by full name.

Example table;

first_name last_name email ...
John Doe john@doe.com ...

Using standard Nova search, the term John Doe will not match this record as neither first name or last name match.

By adding a sub-array of column names into the $search property of a Resource, this package allows searching on concatenated database fields:

class User extends Resource
{
    use Shepp\NovaConcatSearch\Traits\SearchesOnConcatColumns;

    public static $search = [
        ['first_name', 'last_name'], // <----
        'email',
    ];

    // ...
}

This is effectively appending the following to the search query;

WHERE
    # ...
    OR CONACT(first_name, ' ', last_name) LIKE '%John Doe%'

Using the example above, this will allow the term John Doe to match the sample record.