The problem is that you're building an array and then appending that array to your active query string key. That means that if you have an array that looks like [1, 2, 3], it will be converted to a 1,2,3 string. Then on the backend, you get the active key from your query string, and you get a string containing 1,2,3 instead of an array.
What you need to do is send something like this to receive an array on the backend: &query[active][]=1&&query[active][]=2&query[active][]=3.
An even easier and cleaner way would be the following syntax (which would solve your problem by automatically using the right query string syntax for arrays). However, if you want to use that syntax, you will need to use and import the qs library to stringify your data (see here).
axios.get(url, {
params: {
pagination: {
page: context.page,
pages: context.pages,
per_page: context.per_page,
total: context.total
},
sort: {
field: context.sort_field,
sort: context.sort_direction
},
query: {
category: context.category,
brand: context.brand,
active: context.active_filters
}
},
paramsSerializer: params => (
qs.stringify(params)
)
})
.then((resp) => {
console.log(resp.data);
context.products = resp.data.products;
context.categories = resp.data.categories;
context.brands = resp.data.brand;
context.page = resp.data.page;
context.pages = resp.data.pages;
context.per_page = resp.data.per_page;
context.total = resp.data.total;
context.sort_direction = resp.data.sort;
context.sort_field = resp.data.field;
});
However, if you don't want to use a query string serialization library, you can limit the deep nesting to one level, which would give you what you want:
axios.get(url, {
params: {
'pagination[page]': context.page,
'pagination[pages]': context.pages,
'pagination[per_page]': context.per_page,
'pagination[total]': context.total,
'sort[field]': context.sort_field,
'sort[sort]': context.sort_direction,
'query[category]': context.category,
'query[brand]': context.brand,
'query[active]': context.active_filters
}
})
.then((resp) => {
console.log(resp.data);
context.products = resp.data.products;
context.categories = resp.data.categories;
context.brands = resp.data.brand;
context.page = resp.data.page;
context.pages = resp.data.pages;
context.per_page = resp.data.per_page;
context.total = resp.data.total;
context.sort_direction = resp.data.sort;
context.sort_field = resp.data.field;
});