Backend Boilerplates
php
Advanced
Laravel Macro for Query Filters
Extend Laravel Query Builder with a reusable filter macro for API filtering.
php
// AppServiceProvider@boot
Builder::macro("filters", function (array $allowed, Request $request) {
foreach ($allowed as $field) {
if ($request->filled($field)) {
$this->where($field, $request->input($field));
}
}
return $this;
});
// Usage in controller
Module::query()
->filters(["category_slug", "level", "language"], $request)
->published()
->paginate(12);
Prerequisites
- Laravel >= 10
Pro Tips
- → Add orWhere and LIKE support for text search fields.
Commercial Licensing
Acquire a production access token or template license for enterprise deployment.
Module Info
- Language
- php
- Level
- Advanced
- Read time
- 4 min
- Published
- Sep 2025
- License
- Commercial License
Newsletter
New modules every week, directly to your inbox.
Similar Modules
Laravel Artisan Seeder Command
Artisan command to re-seed production data with a confirmation prompt.
php
·
Intermediate
CSV to PostgreSQL Bulk Loader
Stream a large CSV directly into PostgreSQL using COPY for maximum throughput.
python
·
Intermediate
Go Event Sourcing Store
Minimal append-only event store in Go backed by a Postgres table.
go
·
Advanced