refactor(model): use reflection for search field discovery

This commit is contained in:
kj
2026-09-05 00:39:16 -03:00
parent 2ae9ef39f3
commit 9027f36748

View File

@@ -1098,8 +1098,18 @@ class Model
public static function search(string $search, ?array $in = null): static
{
if ($in == null) {
$className = get_called_class();
$in = array_keys((new $className())->getVars());
$in = [];
$reflection = new \ReflectionClass(get_called_class());
foreach ($reflection->getProperties(\ReflectionProperty::IS_PUBLIC) as $property) {
if (!in_array($property->getName(), static::$dbIgnoreSave)) {
$in[] = static::camelCaseToSnakeCase($property->getName());
}
}
}
if (empty($in)) {
return new static();
}
$search = static::bind($search);