spatie / laravel-query-builder

Easily build Eloquent queries from API requests

Home Page:https://spatie.be/docs/laravel-query-builder

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

the-dijkstra opened this issue · comments

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.

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!

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.