Download the PHP package firevel/filterable without Composer

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

Laravel Filterable

A lightweight trait for Laravel Eloquent models that makes it easy to build dynamic, type‐safe filters on your queries. Instead of hard‐coding dozens of scopes or query clauses, simply declare which fields are “filterable” and let the trait handle operators, casting, and relationship logic for you.


Table of Contents

  1. Installation
  2. Quick Start
  3. Configuration
    • Defining $filterable
    • Allowed Filter Types
    • Supported Operators
    • Validating Columns
  4. Basic Usage
    • Filtering by Single Field
    • Filtering by Multiple Fields
    • Composite (“Virtual”) Filters
  5. Advanced Filters
    • Filtering JSON Columns
    • Filtering Relationships
    • Boolean & Null Checks
  6. Examples
  7. Tips & Best Practices
  8. Troubleshooting

Installation

Install via Composer:

Once installed, there are no service‐provider registrations or config publishes required. The trait is ready to use.


Quick Start

  1. Add the Filterable trait to your Eloquent model.
  2. Define a protected $filterable array, mapping each filter key to its type.
  3. Call the filter([...]) scope on your queries.

Now you can do:

––

Configuration

Defining $filterable

In each model that uses the trait, declare a protected $filterable array. The keys are the names (or aliases) you wish to filter on, and the values specify the field’s type. For example:

The trait will only apply filters for keys explicitly declared in $filterable; any others are ignored by default (or throw an exception if you enable column validation).


Allowed Filter Types

Type Description
integer Integer columns or numeric IDs
id Shorthand for integer when representing a primary/foreign key
string Text columns; used with operators like like, =, <>
date Date‐only filters (YYYY‐MM‐DD). Under the hood, uses whereDate()
datetime Date & time filters (YYYY‐MM‐DD HH:MM:SS). Uses whereDate() if value is 10 chars long
boolean Casts “true”/“false” (case‐insensitive) to boolean
json JSON columns; used with where() or JSON operators
array JSON columns containing arrays; uses whereJsonContains()
relationship Expect a related model or “has” filter on a belongsTo / hasMany style relationship

Supported Operators

By default, the trait allows the following operators for each filter type. To override operators on a field, simply pass an associative array ('[ operator ] => [ value ]').

Operator Meaning Allowed Types
= Equal to (default if no operator provided) integer, id, string, date, datetime,
relationship, boolean, json, array
<> Not equal to integer, id, string
> Greater than integer, date, datetime, id, relationship
>= Greater than or equal integer, date, datetime, id, relationship
< Less than integer, date, datetime, id, relationship
<= Less than or equal integer, date, datetime, id, relationship
like SQL LIKE (for partial string matches) string
in SQL IN (for lists or comma‐separated values) integer, id, string, json
is IS NULL check (pass 'null' as value) integer, date, datetime, id, string, boolean, json, array
not IS NOT NULL (pass 'null' as value) integer, date, datetime, id, string, boolean, json, array

Note: If you supply a plain scalar (e.g. 'foo') instead of ['=' => 'foo'], the trait assumes the = operator by default.


Validating Columns

By default, the trait will ignore any filters whose key is not in $filterable. If you’d rather throw an exception when an unknown filter is passed, enable column validation:

With $validateColumns = true, passing ->filter(['not_a_column' => ['=' => 5]]) will throw:


Basic Usage

Filtering by Single Field

Filter on one attribute by providing a key‐value pair. If you omit the operator, it defaults to =.

Filtering by Multiple Fields

Combine as many filters as you need; they are joined with AND logic:


Composite (“Virtual”) Filters

Sometimes you want a single filter key (e.g. name) that actually applies to multiple columns (like first_name OR last_name). You can achieve this by declaring a “scope”-type entry in $filterable and then adding a local scope method on your model.

Example: “name” → searches first_name OR last_name

  1. Declare a scope filter key
    In User.php:

  2. Use it in your code exactly like any other filter

    Under the hood, the trait sees 'name' => 'scope' and calls $query->name('Smith'), which in turn applies:

Why use a “scope”-type filter?


Advanced Filters

Filtering JSON Columns

If you have a JSON column (e.g. meta), you can:


Filtering Relationships

If you want to filter on related models (e.g. User hasMany Order), declare the key as relationship in $filterable. Then pass either:

  1. A scalar/array (for simple has() checks).
  2. A nested filter array to apply conditions on the related model.

Tip: If you need a more complex subquery on the relationship, you can chain useRelationshipQuery() before calling filter().


Boolean & Null Checks


Examples

Below are a few real‐world scenarios illustrating how you might combine filters.


Tips & Best Practices


Troubleshooting


With this simple trait, you can keep your controllers and repositories neat, DRY, and expressive—no more copy/pasting dozens of if ($request->has('…')) { … } checks. Happy filtering!


All versions of filterable with dependencies

PHP Build Version
Package Version
No informations.
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 firevel/filterable contains the following files

Loading the files please wait ....