Skip to content

scope filter not pass all parameters after comma #334

Closed
@J4si3k

Description

@J4si3k

If I make request

GET /?filter[category]=techniczne,klimatyzacja

and use the fallowing filter:

public static function scopeCategory(Builder $query, $value): Builder
    {
        $categoryNames = explode(',', $value);

        dump($categoryNames);

        return $query->whereHas('categories', function($query) use ($categoryNames) {
            $query->whereIn('name', $categoryNames);
        });
    }

then in $value I receive only first string from category filter (in this case "techniczne"). Why am I losing other arguments? In standard filter it works fine.
Maybe can I pass ith in $request->query('filter')['category'] somehow?

my query looks like this:

    public function getFiltredTrainings($request, $perPage = 10) {
      
        $page = $request['page'] ? $request['page'] : 1;

        return QueryBuilder::for(TrainingModel::class)
            ->allowedFilters([
                AllowedFilter::scope('category'),
            ])
            ->defaultSort('created_at')
            ->paginate($perPage, ['*'], 'page', $page)
            ->appends(request()->query());
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions