JavaScript Query Builder provides an easy way to build a query string compatible with spatie/laravel-query-builder.
npm install @limitless.claver/laravel-query-builder
!GitHub Workflow Status
!GitHub issues
!GitHub top language
!npm

The spatie function is a URL builder that allows you to easily add query parameters to a URL using a fluent interface compatible with spatie/laravel-query-builder.
``bash`
yarn add @limitless.claver/laravel-query-builderspatieUsage
To use the function, simply call it with a URL string as its argument. The returned object has three filter
methods: , include, and sort, which can be chained together to build the desired URL.
`javascript`
const {spatie} = require("@limitless.claver/laravel-query-builder");
javascript
const url = 'https://example.com';const result = spatie(url)
.filter('status', 'published')
.include('author', 'categories')
.sort('title', '-date')
.build();
console.log(result);
// Outputs: https://example.com?filter[status]=published&include=author,categories&sort=title,-date
`Methods
$3
Adds a filter query parameter to the URL. The
key argument is the name of the filter, and the value argument is the value of the filter.
If the URL already has query parameters, the filter is added with an ampersand (&) separator. Otherwise, the filter is added with a question mark (?) separator.>Example:
`javascript
const url = 'https://example.com/posts';const result = spatie(url)
.filter('status', 'published')
.build();
console.log(result);
// Outputs: https://example.com/posts?filter[status]=published
`
$3
Adds an include query parameter to the URL. The value argument can be a string or an array of strings.If the URL already has an include parameter, the new values are appended to the existing ones. Otherwise, a new include parameter is added.
>Example:
`javascript
const url = 'https://example.com/posts';const result = spatie(url)
.include('author', 'categories')
.build();
console.log(result);
// Outputs: https://example.com/posts?include=author,categories
`
$3
Adds a sort query parameter to the URL. The field argument can be a string or an array of strings.
If the URL already has a sort parameter, the new values are appended to the existing ones. Otherwise, a new sort parameter is added.> Example:
`javascript
const url = 'https://example.com/posts';const result = spatie(url)
.sort('title', '-date')
.build();
console.log(result);
// Outputs: https://example.com/posts?sort=title,-date
`
$3
Adds a query parameter to the URL. The condition argument must be a boolean.
And the callback should would return an interface for further chaining or building.> Example
`javascript
const url = 'https://example.com/posts';const result = spatie(url).include('author')
.when('claver'.length > 5, q => q.sort('-title'))
.sort('name')
.filter("status","Published").build()
console.log(result);
// Outputs: https://example.com/posts?include=author&sort=-title,name&filter[status]=Published
`
$3
Returns the built URL string.> Example
`javascript
const url = 'https://example.com/posts';const result = spatie(url)
.filter('status', 'published')
.include('author', 'categories')
.sort('title', '-date')
.build();
console.log(result);
// Outputs: https://example.com/posts?filter[status]=published&include=author,categories&sort=title,-date
``