Skip to content

Filter Operations

Filter operations are used to apply specific conditions to the data being queried. They help in narrowing down the results based on various criteria. Filter operations are registered in the config/datagrids.php file under the filter_operations key. Each filter operation class must extend the AbstractFilterOperation class and implement the FilterOperationContract interface.

Configuration

The filter operations are configured in the config/datagrids.php file:

php
<?php

return [
    'filter_operations' => [
        // Equality
        EqualsFilterOperation::class,
        DoesNotEqualFilterOperation::class,

        // Dates
        DateAfterFilterOperation::class,
        DateBeforeFilterOperation::class,
        DateIsFilterOperation::class,
        DateIsNotFilterOperation::class,
        DateOnOrBeforeFilterOperation::class,
        DateOnOrAfterFilterOperation::class,

        // In
        InFilterOperation::class,
        NotInFilterOperation::class,

        // Numeric
        GreaterThanFilterOperation::class,
        GreaterThanOrEqualToFilterOperation::class,
        LessThanFilterOperation::class,
        LessThanOrEqualToFilterOperation::class,

        // String
        ContainsFilterOperation::class,
        DoesNotContainFilterOperation::class,
        EndsWithFilterOperation::class,
        StartsWithFilterOperation::class,
    ],
];

This configuration ensures that the specified filters are available for use in the application. Each filter class defines the conditions it can handle and the logic to apply those conditions to the query.

Available Filter Operations

Equality

Filter OperationDescription
EqualsFilterOperationChecks if a value is equal to the specified value.
DoesNotEqualFilterOperationChecks if a value is not equal to the specified value.

Strings

Filter OperationDescription
ContainsFilterOperationChecks if a string contains the specified substring.
DoesNotContainFilterOperationChecks if a string does not contain the specified substring.
EndsWithFilterOperationChecks if a string ends with the specified substring.
StartsWithFilterOperationChecks if a string starts with the specified substring.

Numeric

Filter OperationDescription
GreaterThanFilterOperationChecks if a value is greater than the specified value.
GreaterThanOrEqualToFilterOperationChecks if a value is greater than or equal to the specified value.
LessThanFilterOperationChecks if a value is less than the specified value.
LessThanOrEqualToFilterOperationChecks if a value is less than or equal to the specified value.

Dates

Filter OperationDescription
DateAfterFilterOperationChecks if a date is after the specified date.
DateBeforeFilterOperationChecks if a date is before the specified date.
DateIsFilterOperationChecks if a date is equal to the specified date.
DateIsNotFilterOperationChecks if a date is not equal to the specified date.
DateOnOrBeforeFilterOperationChecks if a date is on or before the specified date.
DateOnOrAfterFilterOperationChecks if a date is on or after the specified date.

Sets

Filter OperationDescription
InFilterOperationChecks if a value is within a specified set of values.
NotInFilterOperationChecks if a value is not within a specified set of values.