optimistdigital/nova-input-filter

An input filter for Laravel Nova

1.1.0 2021-10-01 15:18 UTC

This package is auto-updated.

Last update: 2021-10-31 15:33:29 UTC


README

Latest Version on Packagist Total Downloads

This Laravel Nova package allows you to create simple input filter.

Requirements

  • php: >=7.2
  • laravel/nova: ^3.0

Features

  • Out of the box, works like an additional search field.
  • Inline usage for simple use-cases.

Screenshots

Input filter

Installation

Install the package in to a Laravel app that uses Nova via composer:

composer require optimistdigital/nova-input-filter

Usage

Accepts an array of columns as first parameter and filter name as second parameter. Can optionally pass in multiple columns: ['email', 'id'], similarly to nova's search.

use OptimistDigital\NovaInputFilter\InputFilter;

public function filters(Request $request)
{
    return [
        InputFilter::make()->forColumns(['email'])->withName('Email'),

        // Or

        InputFilter::make(['email'], 'email'),
    ];
}

Customizing

Out of the box, InputFilter works exactly like Nova's search field. If you wish to change it, you can extend the InputFilter class and override apply() function.

use OptimistDigital\NovaInputFilter\InputFilter;

class ExtendedInputFilter extends InputFilter
{
    public function apply(Request $request, $query, $search)
    {
        return $query->where('email', 'like', "%$search%");
    }
}

Credits

License

Nova Input Filter is open-sourced software licensed under the MIT license.