Okay, so the solution was not that hard after all. Lucky me I found getBindings() and setBindings() methods. Here is the updated remove method:
public function remove( Builder $builder ) {
$model = $builder->getModel();
$autofilters = $model->getAutoFilterData();
# Retun if there are no autofilters
if ( ! count( $autofilters ) ) return;
$af_assoc = $this->autoFilterAssoc( $autofilters );
$query = $builder->getQuery();
$bindings = $builder->getBindings();
# Because there are many different possible methods, I'll watch only basic ones.
$bindkey = 0;
# Checking all the where items
foreach ( (array)$query->wheres AS $key => $value) {
if ( strtolower($value['type']) == 'basic' ) $bindkey++;
# If the column is part of the autofilter routine
if ( isset($af_assoc[ $value['column'] ]) ) {
# Remove the related binding
if ( $bindings[$bindkey - 1] == $value['value'] ) {
unset( $bindings[$key] );
}
# Remove where condition
unset( $query->wheres[$key] );
}
}
# Update the query Builder variables
$query->wheres = array_values($query->wheres);
array_values($bindings);
$builder->setBindings( $bindings );
}
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community