https://github.com/aedart/athenaeum-filters
[READ ONLY] Seach filters utilities, based on http query parameters - see https://github.com/aedart/athenaeum
https://github.com/aedart/athenaeum-filters
Last synced: 12 months ago
JSON representation
[READ ONLY] Seach filters utilities, based on http query parameters - see https://github.com/aedart/athenaeum
- Host: GitHub
- URL: https://github.com/aedart/athenaeum-filters
- Owner: aedart
- License: bsd-3-clause
- Created: 2021-11-15T07:51:50.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2025-07-21T08:07:36.000Z (about 1 year ago)
- Last Synced: 2025-07-21T10:13:12.512Z (about 1 year ago)
- Language: PHP
- Size: 134 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Athenaeum Filters
Offers a way to create search and constraint [query filters](https://aedart.github.io/athenaeum/archive/current/database/query), based on received http query parameters, for your [Laravel](https://laravel.com/) application.
## Example
**Your custom filters builder**
By extending the `BaseBuilder` abstraction, you can encapsulate a custom filters builder.
Whenever a http query parameter is matched, a corresponding "processor" is invoked, which is responsible for creating one or more query filters.
```php
namespace Acme\Filters;
use Aedart\Filters\BaseBuilder;
use Acme\Filters\Processors\MySearchProcessor;
use Acme\Filters\Processors\TextProcessor;
use Acme\Filters\Processors\DateProcessor;
use Acme\Filters\Processors\SortProcessor;
class UserFilterBuilder extends BaseBuilder
{
public function processors(): array
{
// Key = http query parameter, value = parameter processor...
return [
'search' => MySearchProcessor::make(),
'name' => TextProcessor::make(),
'created_at' => DateProcessor::make(),
'sort' => SortProcessor::make()
->force(),
// ...etc
];
}
}
```
**In your request**
To use your custom filters builder, create a new instance in your request, e.g. in the [after validation hook](https://laravel.com/docs/8.x/validation#after-validation-hook).
```php
namespace Acme\Requests;
use Illuminate\Foundation\Http\FormRequest;
use Aedart\Contracts\Filters\BuiltFiltersMap;
use Acme\Filters\UserFilterBuilder;
class ListUsersRequest exends FormRequest
{
public BuiltFiltersMap|null $filters = null;
public function after(Validator $validator)
{
// Add filters using your custom builder
$this->filters = UserFilterBuilder::make($this)
->build();
}
// ... remaining not shown ...
}
```
**In your controller**
Lastly, apply the filters directly on your model.
```php
use App\Http\Controllers\Controller;
use App\Models\User;
use Acme\Requests\ListUsersRequest;
class UsersController extends Controller
{
public function index(ListUsersRequest $request)
{
// Apply all requested filters...
return User::applyFilters($request->filters->all())
->paginate(10);
);
}
}
```
## Official Documentation
Please read the [official documentation](https://aedart.github.io/athenaeum/) for additional information.
The mono repository is located at [github.com/aedart/athenaeum](https://github.com/aedart/athenaeum)
## Versioning
This package follows [Semantic Versioning 2.0.0](http://semver.org/)
## License
[BSD-3-Clause](http://spdx.org/licenses/BSD-3-Clause), Read the LICENSE file included in this package