text - 使用纯文本输入筛选 采用 exact 或 contains 条件逻辑。
username:
label: Username
type: text以下属性可用于过滤器。
| Property | Description |
|---|---|
| conditions | for each condition, set to true or false to make it available, or as a string, can be custom SQL statement for selected conditions. Default: true. |
| modelScope | applies a model query scope method to the filter query, can be a model method name or a static PHP class method (Class::method). The first argument will contain the model that the widget will be attaching its value to, i.e. the parent model. |
以下条件可用于筛选。
| Condition | Description |
|---|---|
| equals | is matching the exact text |
| contains | contains the text |
要只允许查找完全匹配的文本,请使用 equals 作为 condition。要查找包含文本任何部分的结果,则将 contains 传递给条件。
username:
label: Username
type: text
conditions:
equals: true您可以将自定义 SQL 作为字符串传递给条件,其中 :value 包含过滤后的值。
username:
label: Username
type: text
conditions:
equals: username = :value
contains: username like %:value%您可以使用以下示例在模型中定义一个自定义的 modelScope。
username:
label: Username
type: text
modelScope: textFilter该 scopeTextFilter 方法定义 其中值位于 $scope->value。
function scopeTextFilter($query, $scope)
{
if ($scope->condition === 'equals') {
$query->where('username', $scope->value);
}
else {
$query->where('username', 'LIKE', "%{$scope->value}%");
}
}