Download the PHP package pradeepdev001/laravel-smart-filter without Composer

On this page you can find all versions of the php package pradeepdev001/laravel-smart-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 laravel-smart-filter

laravel-smart-filter

Tests PHPStan Latest Version on Packagist PHP Version

A powerful, elegant, and extensible Eloquent filtering package for Laravel 8, 9, 10, 11 & 12.

Stop writing repetitive when() chains. Let your URL do the talking.


Requirements


Installation

The service provider and facade are registered automatically via Laravel's package discovery.

Publish the config (optional):


Quick Start

Add the Filterable trait to any Eloquent model:

Then in your controller:

Or chain on an existing query:


Filter Syntax

Equals

Not Equals

Comparisons

LIKE (contains)

IN / NOT IN

BETWEEN / NOT BETWEEN

NULL checks

Boolean

Sorting

Prefix with - for descending. Comma-separate for multiple columns.

Full-text Search

The fields searched are defined by $searchable on the model or searchable_fields in config.

Combining Filters

All filters are combined with AND logic. Mix freely:


Relationship Filtering

SmartFilter uses dot notation to filter across Eloquent relationships. No extra configuration needed — just use the relationship method name followed by the field you want to filter on.

Basic whereHas

Filter users who have at least one published post:

All Phase 1 operators work inside relationship filters:

Nested Relationships

Chain as many levels deep as you need:

Each dot segment is a relationship method name. The last segment is the field on the related model's table.

Many-to-Many

Works with BelongsToMany out of the box:

Existence Checks

Check whether a relationship exists or not, without filtering on a specific field:

Combining with Flat Filters

Relationship filters and flat filters compose naturally with AND logic:

Model Setup for Relationships

Define your Eloquent relationships as normal. No special configuration needed on the related model:

Note: The parent model's $filterable whitelist applies only to the parent's own columns. Fields inside a relationship subquery are validated independently, so posts.title will work even if title is not in the User model's $filterable.


Configuration

After publishing (vendor:publish --tag=smart-filter-config), config/smart-filter.php gives you global control:


Model-Level Configuration

Model properties always take precedence over global config:

Property Type Description
$filterable list<string> Whitelisted fields. Empty = all allowed.
$filterIgnore list<string> Always-blocked fields.
$filterAliases array<string, string> Request param → real column name mapping.
$searchable list<string> Fields used by ?search=.
$filterStrict bool Throw exceptions instead of silently skipping.

Custom Operators

Implement OperatorContract and register it in a service provider:

Use it in the URL:

Or register via config:


Pagination

SmartFilter is fully compatible with all Eloquent pagination methods:


Testing Your Controllers

Pass a custom Request directly to smartFilter() to keep tests fast and HTTP-free:


Architecture

Data flow:


Roadmap

Phase Status Feature
1 ✅ Complete Core operators, sorting, search
2 ✅ Complete Relationship filtering (whereHas, has, nested)
3 🔄 Planned Date filters (today, last_week, this_month…)
4 🔄 Planned JSON column filtering
5 ✅ Complete Custom operator registration
6 ✅ Complete Full config publishing
7 🔄 Planned Performance optimisation & caching
8 🔄 Planned Macros, IDE helpers, PHPStan types
9 ✅ Partial Pest test suite (105 tests, 210 assertions)
10 ✅ Complete README & documentation

FAQ

Q: Does this prevent SQL injection?
A: Yes. All filter values are passed via PDO bound parameters through Eloquent. Field names are validated against an allow-list before interpolation. Input is additionally sanitised at parse time (null bytes and control characters stripped).

Q: Can I use this without the trait?
A: Yes. Resolve FilterBuilder from the container and call apply($builder, $collection) directly.

Q: What happens with unknown filter params?
A: By default they are silently skipped. Set $filterStrict = true on the model (or 'strict' => true in config) to throw InvalidFilterFieldException instead.

Q: Does the parent model's $filterable block relationship fields?
A: No. $filterable on the parent model only applies to the parent's own columns. Fields inside a relationship subquery (posts.title, company.city) use a permissive guard so they're never accidentally blocked by the parent's whitelist.

Q: Which relationship types are supported?
A: HasMany, BelongsTo, BelongsToMany, and HasOne. Any Eloquent relationship that supports whereHas works.

Q: Can I nest relationships more than one level?
A: Yes, unlimited depth. ?company.address.city=London works, as does ?org.department.team.lead_name=Alice.


Contributing

See CONTRIBUTING.md.

Security

See SECURITY.md. Please do not open public issues for vulnerabilities.

Changelog

See CHANGELOG.md.

License

MIT — see LICENSE.


All versions of laravel-smart-filter with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
illuminate/contracts Version ^8.83 || ^9.0 || ^10.0 || ^11.0 || ^12.0
illuminate/database Version ^8.83 || ^9.0 || ^10.0 || ^11.0 || ^12.0
illuminate/http Version ^8.83 || ^9.0 || ^10.0 || ^11.0 || ^12.0
illuminate/support Version ^8.83 || ^9.0 || ^10.0 || ^11.0 || ^12.0
illuminate/pipeline Version ^8.83 || ^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 pradeepdev001/laravel-smart-filter contains the following files

Loading the files please wait ...