spatie / laravel-query-builder

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

Comma separated list seems to not work on scopes #856

Closed K2ouMais closed 1 year ago

K2ouMais commented 1 year ago

Hello everyone,

I am using a route like this:

/api/user?filter[userId]=1,2,3

In the controller I use a scope to query the id.

AllowedFilter::scope('userId')

The scope in the model:

public function scopeUserId(Builder $query, $id): Builder
{
    dd($id); // output: 1
    return $query->where('id', $id);
}

The output of dd($id) seems to only be the first value of the comma separated list.

Is this correct? What am I doing wrong? I am expecting it to be 1,2,3.

Thank you in advance.