aedart / athenaeum-filters
Search filter utilities, based on http query parameters
Requires
- php: ^8.2
- aedart/athenaeum-contracts: ^8.17
- aedart/athenaeum-database: ^8.17
- aedart/athenaeum-support: ^8.17
- aedart/athenaeum-utils: ^8.17
- aedart/athenaeum-validation: ^8.17
- illuminate/http: ^v11.35.0
- illuminate/pipeline: ^v11.35.0
- dev-main
- 8.17.0
- 8.16.0
- 8.15.0
- 8.14.0
- 8.13.0
- 8.12.0
- 8.11.0
- 8.10.0
- 8.9.0
- 8.8.0
- 8.7.0
- 8.6.0
- 8.5.0
- 8.4.0
- 8.3.0
- 8.2.0
- 8.1.0
- 8.0.0
- 7.33.0
- 7.32.0
- 7.31.0
- 7.30.1
- 7.30.0
- 7.29.0
- 7.28.0
- 7.27.0
- 7.26.0
- 7.25.0
- 7.24.0
- 7.23.0
- 7.22.1
- 7.22.0
- 7.21.0
- 7.20.0
- 7.19.0
- 7.18.1
- 7.18.0
- 7.17.0
- 7.16.0
- 7.15.0
- 7.14.0
- 7.13.0
- 7.12.0
- 7.11.3
- 7.11.2
- 7.11.1
- 7.11.0
- 7.10.1
- 7.10.0
- 7.9.1
- 7.9.0
- 7.8.0
- 7.7.2
- 7.7.1
- 7.7.0
- 7.6.0
- 7.5.0
- 7.4.0
- 7.3.0
- 7.2.0
- 7.1.0
- 7.0.1
- 7.0.0
- 7.0.0-alpha.1
- 6.8.1
- 6.8.0
- 6.7.0
- 6.6.0
- 6.5.2
- 6.5.1
- 6.5.0
- 6.4.0
- 6.3.0
- 6.2.1
- 6.2.0
- 6.1.1
- 6.1.0
- 6.0.2
- 6.0.1
- 6.0.0
- 5.27.0
- 5.26.0
- 5.25.0
- 5.24.2
- 5.24.1
- 5.24.0
- 5.23.0
- 5.22.4
- 5.22.3
- 5.22.2
- 5.22.1
- 5.22.0
This package is auto-updated.
Last update: 2024-12-11 07:53:14 UTC
README
Offers a way to create search and constraint query filters, based on received http query parameters, for your Laravel 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.
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.
namespace Acme\Requests; use Illuminate\Foundation\Http\FormRequest; use Aedart\Contracts\Filters\BuiltFiltersMap; use Acme\Filters\UserFilterBuilder; class ListUsersRequest exends FormRequest { public ?BuiltFiltersMap $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.
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 for additional information.
The mono repository is located at github.com/aedart/athenaeum
Versioning
This package follows Semantic Versioning 2.0.0
License
BSD-3-Clause, Read the LICENSE file included in this package