Download the PHP package illuminatech/data-provider without Composer

On this page you can find all versions of the php package illuminatech/data-provider. 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 data-provider

Laravel Data Provider


This extension allows building of the complex search queries based on the request in Laravel. In particular, it is useful for REST API composition.

For license information check the LICENSE-file.

Latest Stable Version Total Downloads Build Status

Installation

The preferred way to install this extension is through composer.

Either run

or add

to the "require" section of your composer.json.

Usage

This extension allows building of the complex search queries based on the request data. It handles filtering, sorting, pagination, include of extra fields or relations on demand. Both Eloquent Active Record and plain database queries are supported.

This extension provides Illuminatech\DataProvider\DataProvider class, which wraps given data source object like database query builder, and provide the means to define controller-level interaction to search through this data source.

Usage example:

This example will respond to the following request:

Same example with the plain database query usage:

Data provider defines only a few methods for the data querying:

However, you can use prepare() method to get data source object, adjusted to given request, to invoke the method you need. For example:

Method prepare() is immutable, leaving original data source object intact. Thus, you can re-use same data provider to process several different search requests. For example:

Specifying Data Source

There are several ways to specify a data source for the DataProvider:

For example:

Note: this extension does not put explicit restriction on the data source object type - it simply expected to match database query builder notation. Thus, you may create a custom query builder class, which works with special data storage like MongoDB or Redis, and pass its instance as a data source. If its methods signature matches \Illuminate\Database\Query\Builder - it should work. Although it is not guaranteed.

Configuration

You can publish predefined configuration file using following console command:

This will create an application-wide configuration for all DataProvider instances. You can see its example at config/data_provider.php. You may adjust configuration per each DataProvider instance, using second argument of its constructor. For example:

Additional configuration will be merged recursively with one you specified at your "config/data_provider.php" file, so you should specify only those keys you wish to change.

Filtering

Filters setup example:

This example will respond to the following request:

Tip: you may disable filters grouping in request by setting null as data_provider.filter.keyword configuration value.

While specifying filter attribute, you can use a dot ('.') notation to make filter challenge against relation instead of main source. In this case Illuminate\Database\Eloquent\Concerns::QueriesRelationships::whereHas() will be executed under the hood. However, this behavior will apply only for Eloquent query and relations. For example:

List of supported filters:

Please refer to the particular filter class for more details and examples.

You can create your custom filter implementing Illuminatech\DataProvider\FilterContract interface.

Sorting

Sorting setup example:

You may enable multisort support for the data provider setting data_provider.sort.enable_multisort configuration value to true. For example:

Note: sort parameter for multi-sort can be passed both as comma separated string and as an array.

Pagination

Data provider defines following pagination methods, wrapping the ones provided by query builder:

In addition to Laravel standard pagination behavior, these methods also allow control over page size via request parameters. For example:

You may control page size boundaries per each data provider using constructor configuration parameter. For example:

If data_provider.pagination.appends enabled, all pagination methods will automatically append passed request data to the created paginator instance, so you do not need to invoke Illuminate\Contracts\Pagination\Paginator::appends() manually.

Include Relations

While creating an API, you may allow its client to "expand" particular entities, including their relations to the HTTP response.

Available for inclusion relations setup example:

Selecting Fields

While creating an API, you may allow its client to specify the list of fields to be returned by particular listing endpoint. This may be useful to reduce HTTP traffic, skipping large text fields in response.

Selectable fields setup example:

You may specify selectable fields for the related models as well. For example:

Note that passing fields for the particular relation causes its eager loading. This way you actually declare "includes" while writing "fields". This may create an inconsistency in your API, as it allows loading of the particular relation via "fields", but does not allow its loading via "includes". It is your responsibility to setup includes() and fields() in consistent way.

JSON API Specification Support

This extension is compatible with JSON API Specification. However, the default configuration for the pagination mismatches it, since it provides compatibility with native Laravel pagination. But you can easily fix this with a proper configuration. For example:

Dedicated Data Providers

You may create a custom data provider class dedicated to the specific use case. Such approach allows to organize the code and keep your controllers clean.

This goal can be easily achieved using Illuminatech\DataProvider\DedicatedDataProvider as a base class. It predefines a set of methods named define*, like defineConfig(), defineFilters() and so on, which you can override, creating a structured custom class. Also note, that unlike other methods, __construct() is exempt from the usual signature compatibility rules when being extended. Thus, you can specify its signature in your class as you like, defining your own dependencies. For example:


All versions of data-provider with dependencies

PHP Build Version
Package Version
Requires illuminate/support Version ^5.8 || ^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.0 || ^11.0 || ^12.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 illuminatech/data-provider contains the following files

Loading the files please wait ....