Skip to content
A Laravel Nova column queryer filter
Branch: master
Clone or download
Latest commit 8320e93 Feb 25, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
dist Fix filter options Feb 20, 2019
resources/js Fix filter options Feb 20, 2019
src Changed the store getters and setters to match new Nova methods Feb 4, 2019
.gitignore Initial commit Nov 5, 2018
LICENSE Initial commit Nov 5, 2018
README.md Update README.md Feb 25, 2019
composer.json Update composer.json Feb 25, 2019
package.json Initial commit Nov 5, 2018
webpack.mix.js Add compat for custom-filters in Nova@v1.1.8 Nov 22, 2018

README.md

Column Filter for Laravel Nova

A Laravel Nova column querier filter for Nova > v1.1.8

Prior to Nova v.1.3.2, use the 0.2.1 version.

Prior to Nova v.1.1.8, use the 0.1.1 version.

Demo

Demo

Installation

Run this command in your Laravel Nova project:

composer require philperusse/nova-column-filter

Usage

Create a filter with artisan

 $ php artisan nova:filter UserColumnFilter 

Extend your filter class with the ColumnFilter class instead of Nova's base Filter class and add the columns on which you want to filter on in the options

use \philperusse\Filters\ColumnFilter as Filter;

class ColumnFilter extends Filter
{
  
   /**
    * Apply the filter to the given query.
    *
    * @param  \Illuminate\Http\Request  $request
    * @param  \Illuminate\Database\Eloquent\Builder  $query
    * @param  mixed  $value
    * @return \Illuminate\Database\Eloquent\Builder
   */	 
  public function apply( Request $request, $query, $value )
  {
     $args = collect($value)->values()->filter(); //Remove any empty keys.
     if($args->isEmpty())
          return $query;
		  
      return $query->where(...$args->all());
  }
  
  /**
   * Get the filter's available options.
   *
   * @param  \Illuminate\Http\Request  $request
   * @return array
   */
  public function options( Request $request ) : array
    {
        return array_merge(parent::options($request), [
            'columns' => [
                'name'      => 'Name',
                'age'       => 'Age',
            ]
        ]);
    }
}

Customization

You can customize the operator list by overriding the operators key in the filters options.

use philperusse\Filters\ColumnFilter as Filter;

class ColumnFilter extends Filter
{
    public function options( Request $request ) 
    {
        return array_merge(parent::options($request), [
            'columns' => [
                'name'      => 'Name',
                'age'       => 'Age',
            ],
            'operators' => [
                '='     => '=',
                '>'     => '>',
                '>='    => '≥',
                '<'     => '&lt;',
                '<='    => '&le;',
            ]
        ]);
    }

    protected function componentName()
    {
        return 'column-filter';
    }
}

Contributions

All contributions are welcomed. Please send a PR

Authors

The filter is loosely-based on 64Robots's Date Filter and its custom filter selector component

License

This package is open-sourced software licensed under the MIT Licence

You can’t perform that action at this time.