spatie / laravel-query-builder

Easily build Eloquent queries from API requests
https://spatie.be/docs/laravel-query-builder
MIT License
4k stars 392 forks source link

Regression after Laravel version v10.16.1 (Filters no more ignoring null values in request) #882

Closed the-dijkstra closed 11 months ago

the-dijkstra commented 1 year ago

Description

TDLR: I think there is a bug after installing Laravel@v10.16.1

After updating a Laravel project a new patch version of Laravel has been installed (v10.16.0 => v10.16.1), The package is no more ignoring null values in the request as expected.

Previous behavior

$cars = QueryBuilder::for(Car::class)
            ->allowedFilters([
                AllowedFilter::custom('created_between', new FilterByCreatedBetween()),
            ])
            ->get();

// Payload
$payload = [
    'filter' => [
        'created_between' => "",
    ],
];

This works as expected all cars are returned, and filter will be ignored.

New behavior (after installing laravel/framework@v10.16.1)

$cars = QueryBuilder::for(Car::class)
            ->allowedFilters([
                AllowedFilter::custom('created_between', new FilterByCreatedBetween()),
            ])
            ->get();

// Payload
$payload = [
    'filter' => [
        'created_between' => "",
    ],
];

This will not work properly and no results are returned, since the created_between will be passed as a null to the filter.

Notes

I was not able to pin point, why exactly this is happening or what commit specifically broke this package.

AlexVanderbist commented 12 months ago

Hey, thanks for reporting this. Our test suite seems to be passing for both Laravel 10 versions you suggested. It'd be super helpful if you could send a pull request with a failing test for this (or even a fix if you can find the problem altogether). Thanks!

the-dijkstra commented 11 months ago

Hey again, Not able to reproduce this on a standalone repo, maybe the problem was with my codebase, so I'm closing this issue. thanks.