Download the PHP package miracuthbert/laravel-eloquent-filters without Composer

On this page you can find all versions of the php package miracuthbert/laravel-eloquent-filters. 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 laravel-eloquent-filters

Laravel Eloquent Filters

A package for Laravel that can be used to filter a model's records.

How does it work?

Simply the package checks the request query for keys that match the corresponding filter keys set for the model then builds the query.

Each model has a corresponding filters file where it's filters can be registered and mapped.

Each registered filter is a unique file that contains the necessary functionality to build a query.

This means that for models that have a title column, they can share the call the same filter file hence reducing code duplication.

Installation

Use composer to install the package:

Setup

The package takes advantage of Laravel Auto-Discovery, so it doesn't require you to manually add the ServiceProvider.

If you don't use auto-discovery, add the ServiceProvider to the providers array in config/app.php

If you want to publish the config file use the commands below in your console

Publish Config

Usage

Setting up a model

A filter for a model generally extends the Miracuthbert\Filters\FiltersAbstract.

It contains a list of filters that will should be applied to a the model and a map of key/value pair of filters list.

To create one:

First, create a model with php artisan make:model command.

Then create a filter file for the model using:

Switch name with the model name and preferably add suffix Filters to indicate it is a model filter, eg. UserFilters

Copy and add the block of code printed out in the console, to the related model. Do not forget to pull in the required namespaces.

Using Filter in Controller

After setup above in any controller that you call the model instance, call the filter scope passing an instance of the `Illuminate\Http\Request'.

In case you have disabled appending of the filters query to a paginator, you could do it manually by using the filters_query helper:

Creating a Filter

All created filters by default will be placed within, App\Filters directory (namespace).

To create a filter use:

Switch name with the name of the filter, eg. NameFilter (normal filter), CreatedOrder (ordering filter)

When creating a filter, it is good to add Filter or Order to the name for ease of use.

You can then open the filter file and add your custom query functionality. See the filter:make command options for some preset templates.

Filters are basically blocks of code that extend Illuminate\Database\Eloquent\Builder, so you are not limited to the preset templates.

You can pass, the following options to the filter:make command, to make use of some of the common filter templates:

Registering Filters to Model Filters

After creating a filter, to use it open a model filter and register a key/value pair under the $filters field.

Setting Default Filters

In a model filter, you can register a key/value pair under the $defaultFilters field, for filters you want to be applied by default.

key should be the same as the one registered on the $filters field, value should be an actual database value.

Note: Default filters should only be used for filters with fixed or unchanging values, eg. true, false

You can override default filters in the constructor of a model filter, by adding different checks.

Console Commands

There available commands within the package:

Pass --help option to the commands to get more details on using them

Security Vulnerabilities

If you discover a security vulnerability, please send an e-mail to Cuthbert Mirambo via [email protected]. All security vulnerabilities will be promptly addressed.

Credits

License

The project is open-sourced software licensed under the MIT license.


All versions of laravel-eloquent-filters with dependencies

PHP Build Version
Package Version
Requires php Version ^7.3|^8.0
illuminate/console Version >=6.0
illuminate/database Version >=6.0
illuminate/http Version >=6.0
illuminate/support Version >=6.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 miracuthbert/laravel-eloquent-filters contains the following files

Loading the files please wait ....