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. |
以下 conditions 可用于过滤。
| 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: textFilterscopeTextFilter 方法定义其中值位于 $scope->value 中。
function scopeTextFilter($query, $scope)
{
if ($scope->condition === 'equals') {
$query->where('username', $scope->value);
}
else {
$query->where('username', 'LIKE', "%{$scope->value}%");
}
}