Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 2 years ago.
0

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 );

	}
Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

orosznyet orosznyet Joined 6 Apr 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.