refactor(model): use reflection for search field discovery
This commit is contained in:
@@ -1098,8 +1098,18 @@ class Model
|
|||||||
public static function search(string $search, ?array $in = null): static
|
public static function search(string $search, ?array $in = null): static
|
||||||
{
|
{
|
||||||
if ($in == null) {
|
if ($in == null) {
|
||||||
$className = get_called_class();
|
$in = [];
|
||||||
$in = array_keys((new $className())->getVars());
|
$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);
|
$search = static::bind($search);
|
||||||
|
|||||||
Reference in New Issue
Block a user