/** * Return array for filter users * * @return array */ public function getFilter() { $return = []; if ($this->isValid()) { foreach ($this->fields as $field) { if (Str::length($field->getValue()) > 0) { if ($field instanceof TextField) { $return['%' . $field->getName()] = $field->getValue(); } elseif ($field instanceof DateField) { if (Str::endsWith($field->getName(), '_FROM')) { $key = Str::substr($field->getName(), 0, Str::length($field->getName()) - 5); $return['>=' . $key] = $field->getValue(); } elseif (Str::endsWith($field->getName(), '_TO')) { $key = Str::substr($field->getName(), 0, Str::length($field->getName()) - 3); $return['<=' . $key] = $field->getValue(); } else { $return[$key] = $field->getValue(); } } else { $return[$field->getName()] = $field->getValue(); } } } } else { if ($this->getErrors()->has()) { $mess = implode(',', $this->getErrors()->all()); throw new \RuntimeException('Filter error: ' . $mess); } } return $return; }