Download the PHP package youcanshop/queryoption without Composer

On this page you can find all versions of the php package youcanshop/queryoption. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package queryoption

Query Option package logo
QueryOption

Tests Total Downloads License

This package helps you manipulate HTTP query data as an object instead of passing an array through different layers of your application.

Usage

Inside a controller we tend to extract the params from the request and send them to our service and then to the repository to perform search, sort or filtering.

From the example above, the QueryOptionFactory helps create the QueryOption object that hold values needed for search, sort and filters. Since in this example we have a Laravel application, we can use a specific factory method to crate directly from Request object.

createFromGlobals() create the QueryOption object from the global $_REQUEST object.
createFromArray(array $attributes) create the QueryOption object from an array passed in param.
createFromIlluminateRequest(Request $request) create the QueryOption object from a Laravel Illuminate request object.
createFromSymfonyRequest(Request $request) create the QueryOption object from a Symfony HTTP foundation request object.

URL Params

Since the QueryOption package parse the URL parameters, we're going to explain the param names below:

q Used for search
search_type (like: default, equal)
page Current page (when working with pagination)
limit Limit query result (when working with pagination)
sort_field Name of the field when sorting (created_at: default)
sort_order Sorting direction. (asc, desc: default)
filters An array of filters (as described below)
field Name of the field to filter by
operator Comparison operator (=: default, !=, >, <, =>, <=, is, is_not, in)
value The value to compare by

Query Option

The QueryOption is the glue that holds all the rest of the components.

For most applications, each controller has a set of filters that are allowed in certain context (admin vs normal user). In this case, you can use the allowedFilters() method inside the controller to limit passing filters in the wrong context.

An example would be listing blog posts. The admin can all the posts, while the normal user can only see the published ones.

Laravel Bridge

For Laravel applications, you can add Query Option provider inside config/app.php

After that you can benefit from helpers like:

Inside your repository you can use what we call criterias. Here's an example on how it works:

So calling the paginate() method will pass the query through the list of criterias to add the necessary logic for each defined query option. Then, we return the modified query instance to continue the pagination.

Below is the code inside each criteria to illustrate how it works.

The search criteria do a search using like or equal using the term when it's not empty, and return the $query and $queryOption for the next criteria.

The sorting is pretty straightforward in this example. An important thing is to guard against sorting using not allowed fields.

This is it, the pagination will take in consideration the fitering by publish date, searching by title and sorting by publish date.


All versions of queryoption with dependencies

PHP Build Version
Package Version
Requires php Version ^7.4 || ^8.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package youcanshop/queryoption contains the following files

Loading the files please wait ....