Download the PHP package claver/smart-query without Composer
On this page you can find all versions of the php package claver/smart-query. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download claver/smart-query
More information about claver/smart-query
Files in claver/smart-query
Package smart-query
Short Description Making queries much easier in your laravel application
License MIT
Informations about the package smart-query
Laravel Smart Query
Introduction
Smart-Query is a Laravel package that utilizes spatie-query-builder to enable smart queries with minimal configuration. With this package, you can create powerful, dynamic queries by simply adding the HasSmartQuery trait to your models.
Installation
To install Smart-Query, you need to have a Laravel application set up. Then, you can install the package via composer by running the command:
After installing the package, you need to register the SmartQueryServiceProvider
in your config > app.php
This will publish the query-builder.php
file to your config
directory.
Usage
To use Smart-Query, add the HasSmartQuery
trait to any model you want to enable smart queries on.
This trait provides a resolve
method, which you can use to apply smart queries to your model.
The smartQuery
method will apply any filters, sorts, includes, and fields specified in the query string to the model.
To learn more about how to make simple and advanced queries, visit Spatie-Query-Builder
You do not have to create your own query builder every single time you need it. Just override these methods.
Method | Description |
---|---|
getAllowedFilters | Returns an array that includes all the fields that could be filtered |
getAllowedIncludes | Returns an array that includes all the relationships that could be included |
getAllowedSorts | Returns an array that includes all the fields that could be sorted. you don't need to include this method because it's dynamically generated |
Conclusion
Smart-Query is a powerful package that simplifies creating dynamic queries in Laravel. By using the HasSmartQuery
trait, you can take advantage of the spatie-query-builder package and create smart queries with minimal configuration.