PHP code example of philperusse / nova-column-filter

1. Go to this page and download the library: Download philperusse/nova-column-filter library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

philperusse / nova-column-filter example snippets


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',
            ]
        ]);
    }
}

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' => [
                '='     => '&equals;',
                '>'     => '&gt;',
                '>='    => '&ge;',
                '<'     => '&lt;',
                '<='    => '&le;',
            ]
        ]);
    }

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