Skip to content

Commit ea2e627

Browse files
committed
改进搜索器方法 支持在未定义搜索器方法的情况下 使用简单规则搜索
1 parent 6069f66 commit ea2e627

File tree

2 files changed

+14
-38
lines changed

2 files changed

+14
-38
lines changed

src/db/concern/ModelRelationQuery.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,13 @@ public function withSearch(string | array $fields, $data = [], bool $strict = fa
235235
if ($strict && (!isset($data[$fieldName]) || (empty($data[$fieldName]) && !in_array($data[$fieldName], ['0', 0])))) {
236236
continue;
237237
}
238+
239+
if (is_string($key) && isset($data[$key])) {
240+
// 默认搜索规则
241+
$this->where($key, $field, 'like' == $field ? '%' . $data[$key] . '%' : $data[$key]);
242+
continue;
243+
}
244+
238245
$method = 'search' . Str::studly($fieldName) . 'Attr';
239246
$entity = $this->model->getEntity();
240247
if ($entity && method_exists($entity, $method)) {

src/model/View.php

Lines changed: 7 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -313,42 +313,6 @@ protected function getData(): array
313313
return $data;
314314
}
315315

316-
/**
317-
* 设置需要附加的输出属性.(视图模型下无效)
318-
*
319-
* @param array $append 属性列表
320-
*
321-
* @return $this
322-
*/
323-
public function append(array $append)
324-
{
325-
return $this;
326-
}
327-
328-
/**
329-
* 设置需要隐藏的输出属性.(视图模型下无效)
330-
*
331-
* @param array $hidden 属性列表
332-
*
333-
* @return $this
334-
*/
335-
public function hidden(array $hidden)
336-
{
337-
return $this;
338-
}
339-
340-
/**
341-
* 设置需要输出的属性.(视图模型下无效)
342-
*
343-
* @param array $visible
344-
*
345-
* @return $this
346-
*/
347-
public function visible(array $visible)
348-
{
349-
return $this;
350-
}
351-
352316
/**
353317
* 判断数据是否为空.
354318
*
@@ -438,7 +402,7 @@ public function bindRelationAttr($model, $bind, $relation)
438402
*
439403
* @return array
440404
*/
441-
protected function convertData(): array
405+
private function convertData(): array
442406
{
443407
// 获取属性映射
444408
$properties = $this->getEntityPropertiesMap();
@@ -504,7 +468,7 @@ public function scene(string|array $scene)
504468
* @throws ValidateException
505469
* @return bool
506470
*/
507-
protected function validate(): bool
471+
private function validate(): bool
508472
{
509473
$validater = $this->getOption('validate');
510474
if (!empty($validater) && !$this->getOption('dataHasValidate', false)) {
@@ -768,6 +732,11 @@ public static function __callStatic($method, $args)
768732

769733
public function __call($method, $args)
770734
{
735+
if (in_array($method, ['hidden', 'visible', 'append'])) {
736+
// 不支持输出设置
737+
return $this;
738+
}
739+
771740
// 调用Model类方法
772741
$result = call_user_func_array([$this->model(), $method], $args);
773742
return $result instanceof Model ? $this : $result;

0 commit comments

Comments
 (0)