Skip to content

Luke-Shepp/nova-search-concat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Laravel Nova Concat Search

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.

About

Search by Concatenated fields in Laravel Nova

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages