Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

9.2.0 #609

Merged
merged 5 commits into from
Jul 1, 2024
Merged

9.2.0 #609

merged 5 commits into from
Jul 1, 2024

Conversation

binaryk
Copy link
Collaborator

@binaryk binaryk commented Jul 1, 2024

Added

Handling Additional Payload Data in Advanced Filters

In some scenarios, you might want to send additional data beyond the standard key and value in your filter payload. For instance, you may need to specify an operator or a column to apply more complex filtering logic. Laravel Restify Advanced Filters provide a way to handle these additional payload fields using the $this->rest() method.

Example Payload

Consider the following payload:

const filters = btoa(JSON.stringify([
    {
        'key': ValueFilter::uriKey(),
        'value': 'Valid%',
        'operator' => 'like',
        'column' => 'description',
    }
]));

const response = await axios.get(`api/restify/posts?filters=${filters}`);

In this payload, besides the standard key and value, we are also sending operator and column. The operator specifies the type of SQL operation, and the column specifies the database column to filter.

Using $this->rest() to Access Additional Data

To handle these additional fields in your filter class, you need to ensure they are accessible via the $this->rest() method. Here is how you can achieve that:

class ValueFilter extends AdvancedFilter
{
    public function filter(RestifyRequest $request, Builder|Relation $query, $value)
    {
        $operator = $this->rest('operator');
        $column = $this->rest('column');

        $query->where($column, $operator, $value);
    }

    public function rules(Request $request): array
    {
        return [];
    }
}

Copy link

what-the-diff bot commented Jul 1, 2024

PR Summary

The following list summarizes the introduced changes:

  • Enhancing Search Documents: A new object was added to the response array in advanced-filters.md in the docs-v2/content/en/search directory, expanding the possibilities for filtering search results.

  • Improvement in Code Quality: The empty bodies of numerous classes, interfaces, and traits throughout the src directory were removed, which might lead to faster code parsing and execution.

  • AdvancedFilter Functionality: The AdvancedFilter and AdvancedFilterPayloadDataObject classes were improved by adding a rest method and rest property, potentially widening the usage and giving more flexibility.

  • Adjustment to AdvancedFiltersCollection: The $dto object constructor parameters in the AdvancedFiltersCollection class were enriched with two new variables, key and value. This can further help manipulations done with filter objects.

  • Testing Expansion: A new test was added to AdvancedFilterTest for sending meta information in a filter payload. This would enhance the stability and reliability of the feature.

  • Changes in FieldTest: Modifications were made in several FieldTest methods, potentially enhancing the overall test coverage and robustness.

  • ValueFilter Addition: A new class ValueFilter was added, broadening the customization possibilities for the users.

Please note, changes in other files were evaluated as minor or not substantial for the end functionality of the project.

@binaryk binaryk merged commit 7145785 into 9.x Jul 1, 2024
9 of 10 checks passed
@binaryk binaryk deleted the advanced-filters-meta branch July 1, 2024 20:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant