Download the PHP package matthenning/eloquent-api-filter without Composer

On this page you can find all versions of the php package matthenning/eloquent-api-filter. 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 eloquent-api-filter

Eloquent API Filter

Awesome and simple way to create, query and modify Eloquent models through your API - with only a few lines of code.


Concept

When developing API applications, you'll often end up with lots of duplicate code within your controllers. Eloquent API Filter offers a simple way to expose your models through the API by defining a route and a tiny controller. Your controller only needs to use a few traits and you'll have a full CRUD implementation for your model exposed through you API.


Table of Contents

Installation

Package installation

Controller setup

You have the choice to use either of the following methods to leverage the filter. The easiest method out of the box is to simply extend the included controller.

Option 1: Extend the controller (recommended)

The easiest way to use the Eloquent API Filter is to extend its controller. For this example, let's say you have a model named Person. You'll just have to create a matching controller and use the included traits to enable the default methods for index, show, store, update, destroy:

Next you can expose your controller by adding a new route:

Eloquent API Filter will automatically find the matching model class as long as you follow the naming scheme of this example. If you have custom names or namespaces, you can override the modelName property within your controller:

And you're done! Start querying your API following the method guidelines. See https://laravel.com/docs/10.x/controllers#actions-handled-by-resource-controller for actions store, show, index, update, destroy:

Custom Resource

If you're using custom resources (https://laravel.com/docs/master/eloquent-resources) you can define a resourceName property on your models. Otherwise the default resource will be used. Make sure to override the toArray and call enrich() with your data. The enrich method will make sure all eager loaded relations (/model?with[]=relation1,relation2) are also transformed by their respective resource.

In your Person model:

In your PersonResource:

Option 2: Use the trait

If you'd like to handle the controller and resource logic yourself entirely, can use the FiltersEloquentApi trait in your controller.

Option 3: Query the filter directly

If traits are not to your taste you can also initialize Eloquent API Filter yourself.


Queries

Filtering

URL Syntax

Filter with specific operator:

Filter for equality:

Operators:

Examples

Matches all entities where name starts with Rob and deceased is null:

Multiple filters on one field can be chained. Matches all entities where created_at is between 2016-12-10 and 2016-12-08:

Filter by related models' fields by using the dot-notaion. Matches all Posts of Persons where Post name contains "API"

Get all persons with name Rob and Bob

Special filters

Timestamps

Matches all persons whos' birthdays are today

Sorting

URL Syntax

Examples

Limit and sorting. Matches the top 10 persons with age of 21 or older sorted by name in ascending order

Select fields

Select only specific columns. Might need additional work on your model transformation.

URL Syntax

Examples

Joins

URL Syntax

Examples

Join posts-relation on persons

Complex filter values

If you need to filter for a value with special characters, you can base64 encode the field to avoid breaking the filter syntax.

URL Syntax

Examples


Responses

Responses always contain two JSON objects data and meta. Data contains the queried models and meta contains for example pagination details.

Example


What if I need more?

In case you need complex queries which are not covered by this library, you can use the EloquentApiFilter trait in your custom controller and further filter the query before retrieving the models. That way you can still use the filter features and only need to add your custom filtering before returning the retrieved models.


All versions of eloquent-api-filter with dependencies

PHP Build Version
Package Version
Requires php Version >=8.2
illuminate/database Version >=9.0
illuminate/http Version >=9.0
illuminate/routing Version >=9.0
illuminate/support Version >=9.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 matthenning/eloquent-api-filter contains the following files

Loading the files please wait ....