Download the PHP package phatnt99/advanced-query without Composer

On this page you can find all versions of the php package phatnt99/advanced-query. 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 advanced-query

advanced-query

A package provides an advanced query for Eloquent Laravel.

Requirements

This package require:

Laravel

The package supports auto-discovery, so if you use Laravel 5.5 or later you may skip this step.

Append the following line to the providers key in config/app.php to add the service provider

Usage

This package support 3 key features: filter, sort and custom query.

To get started, run the bellow Artisan command:

Note: you need to define your model before running this command, the word User in that query name will use to find existed model. If no model corresponds to the name provided, the error will show and cause unexpected behavior (but you can change the correct class model after that).

The --fs option will create class Filter and Sort, if you just custom your query then remove this.

The above command will create 3 files in App\Queries:

Let deep to detail

Filter

Default filter

The package ship with 3 attributes to save your time. Instead of doing this:

You can use this:

It reduces time to write duplicate code and make the class where you perform some filter function more readable :)

Filter date in range

A small tip with date filter, if you want to filter date in range (from...to). Try that:

Custom filter

Sometimes your filter work with complicated logic (like filtering on a relationship attribute), the filter class help you custom your own function to perform complex filter

Then use the function name like attribute name in query string.

Using in query string

You can pass the attribute along with value want to be filter by filters key:

Sort

Default sort

The concrete Sort class has attribute defaultSorts which let you define sortable attributes.

For attribute has constant direction, use enum SortDirection for its value

Note: If the attribute has both a default direction (like above) and a direction in the query string, it will treat direction in the query string as a higher priority.

Using in query string

I use sort key with prefix - to perform descending sort (none is ascending):

Query

This is the class that binds the main functions of the package. You must define some important attributes that point to dependendcy classes

If you use the full command (with --fs option and correct model) it will automatically bind these value for you (or just model class if not using --fs option).

Just specify the dependent classes (with the full handler in each dependency) and you can use the main power of the package.

Allowed attributes

In case you want to restrict only some attributes allowed to be filtered or sorted, pass these attribute to allows argument (the 2nd paramater)

Eloquent Query & Advanced Query

You can use Eloquent methods (where, whereHas,...) directly with an instance of Query class but it will lost the chain (chaining methods). A better way, define your own method which use these Eloquent method and then return the Query instance

Paginate

I use default paginate of Eloquent model which allow you pass the index of expected page into paginate() (default is 1).

Other usage

You can use each feature independently.

Filter & Sort independent

You must set the query attribute to use these independently. Example (the same method for sort):

Instead of passing attributes (with value) into the query string, you can pass it into setAllowAttrs method:

Then you can easily get collection result with getCollection method.

By the way, the package provides 2 separate commands for filter and sort:

Happy Coding!

Contributing

If you find some issue or want to make it better with your code, feel free to make PR or Issue :)

License

The MIT License (MIT)


All versions of advanced-query with dependencies

PHP Build Version
Package Version
Requires php Version ^7.2
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 phatnt99/advanced-query contains the following files

Loading the files please wait ....