Skip to content

Clause API

A clause describes one comparison within a filter. Custom clauses use InertiaX\Components\Table\Filters\Clauses\Clause::make(string $key, ?string $label = null). Custom keys must be namespaced, such as acme/role-equals.

Keys Input
equals, not-equals One value; select filters may use multiple values
contains, not-contains, starts-with, not-starts-with, ends-with, not-ends-with Text
greater-than, greater-than-or-equal, less-than, less-than-or-equal Number
between, not-between Ordered two-value range
before, after Date, datetime, or time
is-set, is-not-set No input; state value is null

The corresponding ClauseType enum is in InertiaX\Components\Table\Filters\Clauses\Enums. For example, ClauseType::Contains->make() creates the built-in contains clause. Text-pattern clauses support caseSensitive(?bool $value = true); the default comes from Filter::$defaultCaseSensitive, initially false. Database comparison behavior can vary by collation.

Method Contract
modifyUsing(Closure $modifier) Append an input transformation
validateUsing(?Closure $validator) Return Boolean acceptance of the normalized value
applyUsing(?Closure $callback, DataSourceKind|string ...$sources) Apply the comparison to a supported source
supports(DataSourceKind|string ...$sources) Declare source kinds separately

DataSourceKind is in InertiaX\Components\Table\Enums. See Custom filters for a complete comparison example.

For ordinary non-null input, the server checks the built-in filter’s value type, runs modifiers, checks the type again, validates temporal values and range ordering, then calls the custom validator. Namespaced custom filter types do not supply the built-in coarse type check; their clauses must validate the value they expect.

No-input clauses require null. For other clauses, null input is accepted only when the filter is nullable; it bypasses modifiers and the custom validator. Range input must contain exactly two values. Validation happens before query execution.

applyUsing() receives the source, the source field key as $column, and the validated comparison value. It may also request available table, filter, clause, and state context through the callback evaluator. Declare supported source kinds explicitly.

Return the same source kind, or null to retain the incoming source. A custom clause that only implements SQL must declare only DataSourceKind::Eloquent. Unsupported sources and invalid return types fail with contextual exceptions.