number - 使用数值进行过滤并利用 exact, between, greater and lesser 条件逻辑。
age:
label: Age
type: number
conditions:
greater: true以下属性可用于该过滤器。
| Property | Description |
|---|---|
| default | specifies a default value for the filter. |
| 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 |
|---|---|
| exact | is matching the exact number |
| between | is between two supplied numbers |
| greater | is greater than the supplied number |
| lesser | is less than the supplied number |
您可以设置 default 值来设置默认过滤值。
age:
label: Age
type: number
default: 14您可以将自定义 SQL 作为字符串传递给条件其中 :value、:min 和 :max 包含过滤后的值。
age:
label: Age
type: number
conditions:
greater: age >= :value
between: age >= :min and age <= :max您可以使用以下示例在模型中定义一个自定义的 modelScope。
age:
label: Age
type: number
modelScope: numberFilterscopeNumberFilter 方法的定义,其值取自 $scope->value、$scope->min 和 $scope->max。
function scopeNumberFilter($query, $scope)
{
if ($scope->condition === 'equals') {
$query->where('age', $scope->value);
}
elseif ($scope->condition === 'between') {
$query
->where('age', `>=`, $scope->min)
->where('age', `<=`, $scope->max);
}
elseif ($scope->condition === 'greater') {
$query->where('age', `>=`, $scope->value);
}
else {
$query->where('age', `<=`, $scope->value);
}
}