ghostcompiler/laravel-querybuilder
API-ready Eloquent query builder for Laravel with strict allow-lists for filters, sorts, includes, and sparse fields. Supports nested relation filters/sorting, custom filters, tenant scoping, safe public query interfaces, and pagination helpers for clean API responses.
where()/orderBy() calls with package methods (e.g., $query->allowFilter('status')).allowFilter(), allowSort()) and custom filter logic. Provide internal documentation or workshops.Phase 1: Pilot with a Single Model
User, Product).// Before
$query->where('status', 'active')->orderBy('created_at');
// After
$query->allowFilter('status')->allowSort('created_at');
Phase 2: Schema-Driven Refactor
Product:
public function getFilters(): array { return ['status', 'category_id']; }
public function getSorts(): array { return ['name', 'price', 'created_at']; }
Phase 3: Policy & Tenant Integration
Phase 4: Full API Rollout
spatie/laravel-api-resources).baum/baum for CMS).laravel/sanctum for tenant isolation).| Step | Task | Dependencies | Risk Mitigation |
|---|---|---|---|
| 1 | Define schema allow-lists | Model definitions | Start with minimal allow-lists; expand iteratively. |
| 2 | Replace raw queries | Pilot model | Use feature flags to toggle old/new logic. |
| 3 | Add custom filters | Domain logic | Test edge cases (e.g., malformed input). |
| 4 | Integrate policies | Auth system | Mock policies during testing. |
| 5 | Tenant scoping | Multi-tenancy setup | Test with sample tenant data. |
| 6 | Deprecate legacy queries | API versioning | Use middleware to log warnings. |
allowFilter() vs. customFilter()).query_builder.log channel) for auditing.status, created_at).| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Invalid Query Parameters | 400 errors, API instability | Use middleware to sanitize input before reaching package. |
| N+1 Queries in Nested Relations | High DB load, timeouts | Enforce with() allow-lists and use loadMissing(). |
| Schema Mismatch | Broken queries, 500 errors | Implement schema validation in CI/CD. |
| Custom Filter Bugs | Data corruption, leaks | Unit test all custom filters with fuzz testing. |
| Tenant Isolation Failure | Cross-tenant data leaks | Use Laravel’s tenant middleware + package scoping. |
How can I help you explore Laravel packages today?