Download the PHP package forrestedw/query-url-builder without Composer
On this page you can find all versions of the php package forrestedw/query-url-builder. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package query-url-builder
Easy query url building
This packages makes it easy to make the links necessary for use in the front en with spatie/laravel-query-builder. The package is amazing helpful for the back end, and the front end is outside of the scope of the project. Creating the links for the front end can be verbose. This package makes it easy.
Installation
Basic usage
For greatest convenience, use it from the facade.
Sort
Set a sort
Access the sort
Reverse the sort
Remove a sort
Filter
Check if a filter is set
Set filters
Filters can also be set using an associative array:
Remove a filter
Combine various sort
and filter
options
forUrl()
By default, QueryUrl
returns the new query params for the route you are already on:
If you need a different url, use forUrl()
. It accepts plain urls or named routes:
Using in blade
Use the queryUrl()
in your blade files like below.
Sorting
The following example will create a link that cycles through three states of being sorted:
- Sorted A-Z
- Sorted Z-A
- Unsorted.
The url text shows what sort the user will currently be seeing. The link will take the user to the next sort state.
Filtering
A similar approach is taken for boolean value filtering, and cycling through the three states:
- Show
true
only - Show
false
only - Show all
Blade components
For ease, the two above trios of if-else links can be outputted using the following, respectively:
Behind the scenes the sort
or filter
attribute is handled to snake case it for the attribute in question. For example, the sort example displays First Name
(exactly as passed) but sorts for first_name
.