public function scopeFilterColumns($query, $columns = array(), $validate = false)
	{
		if ( sizeof($columns) > 0 ) {
			// Set columns that can be filtered
			$this->setColumns($columns);
		}
		// Validate columns
		if ( $validate ) {
			$this->validateColumns();	
		}
		// Ensure that query string is parsed at least once
		if ( sizeof($this->filterable['filters']) == 0 ) {
			$this->setQuerystring();
		}
		// Apply conditions to Eloquent query object
		if ( sizeof($this->filterable['filters']) > 0 ) {
			foreach ( $this->filterable['filters'] as $k => $v ) {
				$where = $v['boolean'];	
				if ( is_array($v['val']) ) {
					if ( isset($v['val']['start']) && isset($v['val']['end']) ) {
						// BETWEEN a AND b
						$query->whereBetween($k, array($v['val']['start'], $v['val']['end']));
					} else {
						// a = b OR c = d OR...
						$query->{$where}(function($q) use ($k, $v, $query)
						{
							foreach ( $v['val'] as $key => $val ) {
								$q->orWhere($k, $v['operator'], $val);	
							}	
						});
					}
				} else {
					// a = b
					$query->{$where}($k, $v['operator'], $v['val']);
				}
			}
		}
		// Apply callbacks
		if ( sizeof($this->filterable['callbacks']) > 0 ) {
			foreach ( $this->filterable['callbacks'] as $v ) {
				$v($query);	
			}
		}
		// Sorting
		if ( isset($this->filterable['qstring'][$this->filterable['orderby']]) && isset($this->filterable['columns'][$this->filterable['qstring'][$this->filterable['orderby']]]) ) {
			$order = isset($this->filterable['qstring'][$this->filterable['order']]) ? $this->filterable['qstring'][$this->filterable['order']] : 'asc';
			$query->orderBy($this->filterable['columns'][$this->filterable['qstring'][$this->filterable['orderby']]], $order);
		}
		return $query;
	}
public function scopeFilterColumns($query, $columns = array(), $validate = false)
	{
		if ( sizeof($columns) > 0 ) {
			// Set columns that can be filtered
			$this->setColumns($columns);
		}
		// Validate columns
		if ( $validate ) {
			$this->validateColumns();	
		}
		// Ensure that query string is parsed at least once
		if ( sizeof($this->filterable['filters']) == 0 ) {
			$this->setQuerystring();
		}
		// Apply conditions to Eloquent query object
		if ( sizeof($this->filterable['filters']) > 0 ) {
			foreach ( $this->filterable['filters'] as $k => $v ) {
				$where = $v['boolean'];	
				if ( is_array($v['val']) ) {
					if ( isset($v['val']['start']) && isset($v['val']['end']) ) {
						// BETWEEN a AND b
						$query->whereBetween($k, array($v['val']['start'], $v['val']['end']));
					} else {
						// a = b OR c = d OR...
						$query->{$where}(function($q) use ($k, $v, $query)
						{
							foreach ( $v['val'] as $key => $val ) {
								$q->orWhere($k, $v['operator'], $val);	
							}	
						});
					}
				} else {
					// a = b
					$query->{$where}($k, $v['operator'], $v['val']);
				}
			}
		}
		// Apply callbacks
		if ( sizeof($this->filterable['callbacks']) > 0 ) {
			foreach ( $this->filterable['callbacks'] as $v ) {
				$v($query);	
			}
		}
		// Sorting
		if ( isset($this->filterable['qstring'][$this->filterable['orderby']]) && isset($this->filterable['columns'][$this->filterable['qstring'][$this->filterable['orderby']]]) ) {
			$order = isset($this->filterable['qstring'][$this->filterable['order']]) ? $this->filterable['qstring'][$this->filterable['order']] : 'asc';
			$query->orderBy($this->filterable['columns'][$this->filterable['qstring'][$this->filterable['orderby']]], $order);
		}
		return $query;
	}
public function scopeFilterColumns ( $ query , $ columns = array ( ) , $ validate = false ) { if ( sizeof ( $ columns ) > 0 ) { // Set columns that can be filtered $ this -> setColumns ( $ columns ) ; } // Validate columns if ( $ validate ) { $ this -> validateColumns ( ) ; } // Ensure that query string is parsed at least once if ( sizeof ( $ this -> filterable [ 'filters' ] ) == 0 ) { $ this -> setQuerystring ( ) ; } // Apply conditions to Eloquent query object if ( sizeof ( $ this -> filterable [ 'filters' ] ) > 0 ) { foreach ( $ this -> filterable [ 'filters' ] as $ k => $ v ) { $ where = $ v [ 'boolean' ] ; if ( is_array ( $ v [ 'val' ] ) ) { if ( isset ( $ v [ 'val' ] [ 'start' ] ) && isset ( $ v [ 'val' ] [ 'end' ] ) ) { // BETWEEN a AND b $ query -> whereBetween ( $ k , array ( $ v [ 'val' ] [ 'start' ] , $ v [ 'val' ] [ 'end' ] ) ) ; } else { // a = b OR c = d OR... $ query -> { $ where } ( function ( $ q ) use ( $ k , $ v , $ query ) { foreach ( $ v [ 'val' ] as $ key => $ val ) { $ q -> orWhere ( $ k , $ v [ 'operator' ] , $ val ) ; } } ) ; } } else { // a = b $ query -> { $ where } ( $ k , $ v [ 'operator' ] , $ v [ 'val' ] ) ; } } } // Apply callbacks if ( sizeof ( $ this -> filterable [ 'callbacks' ] ) > 0 ) { foreach ( $ this -> filterable [ 'callbacks' ] as $ v ) { $ v ( $ query ) ; } } // Sorting if ( isset ( $ this -> filterable [ 'qstring' ] [ $ this -> filterable [ 'orderby' ] ] ) && isset ( $ this -> filterable [ 'columns' ] [ $ this -> filterable [ 'qstring' ] [ $ this -> filterable [ 'orderby' ] ] ] ) ) { $ order = isset ( $ this -> filterable [ 'qstring' ] [ $ this -> filterable [ 'order' ] ] ) ? $ this -> filterable [ 'qstring' ] [ $ this -> filterable [ 'order' ] ] : 'asc' ; $ query -> orderBy ( $ this -> filterable [ 'columns' ] [ $ this -> filterable [ 'qstring' ] [ $ this -> filterable [ 'orderby' ] ] ] , $ order ) ; } return $ query ; }
Laravel Eloquent query scope.

@param $query Eloquent query object
@return Eloquent query object
Laravel Eloquent query scope .