Download the PHP package baethon/laravel-criteria without Composer
On this page you can find all versions of the php package baethon/laravel-criteria. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download baethon/laravel-criteria
More information about baethon/laravel-criteria
Files in baethon/laravel-criteria
Package laravel-criteria
Short Description Minimal interface for criteria pattern
License MIT
Informations about the package laravel-criteria
baethon/laravel-criteria
Minimal implementation of criteria pattern for Laravel.
What is criteria?
Criteria is an implementation of \Baethon\LaravelCriteria\CriteriaInterface
which is responsible for only one thing - modify Laravels query in a specified way.
This allows to decouple and re-use query modifiers.
Criteria are very similar to Eloquent scopes. The main difference is that they can be applied to different models across the application.
Installation
Requirements
- PHP >= 7.1
Laravel compatibility
This library has no dependencies to Laravel itself. It should work with all versions of Laravel.
Usage
First, you need to create an implementation of CriteriaInterface
:
Now, you can apply it to the query:
AppliesCriteria trait
To simplify things it's possible to use AppliesCriteria
trait in a model.
Collections
The package provides collections which allow applying multiple criteria at once.
To apply group of criteria use \Baethon\LaravelCriteria\Collections\CriteriaCollection
:
If you need to be sure that all criteria will be fulfilled you can use CriteriaCollection::allOf()
:
Also, you can group criteria using logical OR
join:
Testing
Run tests with:
Changelog
Please see CHANGELOG for more information what has changed recently.
License
The MIT License (MIT). Please see License File for more information.