Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Eloquent Builder Laravel Package

mohammad-fouladgar/eloquent-builder

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Query Abstraction: The package excels at abstracting complex query logic from API controllers, aligning with clean architecture principles by decoupling business logic from HTTP concerns. This is particularly valuable in layered architectures (e.g., Laravel’s MVC) where controllers should remain thin.
  • Request-Driven Filtering: Ideal for search APIs, admin dashboards, or dynamic data fetching where query parameters dictate results. Fits well with RESTful and GraphQL endpoints requiring flexible filtering.
  • Eloquent Compatibility: Leverages Laravel’s built-in Eloquent ORM, ensuring seamless integration with existing database interactions. Avoids reinventing query-building wheels.

Integration Feasibility

  • Low Friction: Requires minimal boilerplate—just extend EloquentBuilder and define rules in a config file or service. Reduces repetitive if-else chains in controllers.
  • Customizability: Supports nested relationships, custom conditions, and validation rules, making it adaptable to most Eloquent use cases.
  • Middleware Potential: Can be paired with Laravel middleware to pre-process requests before query execution, centralizing filtering logic.

Technical Risk

  • Stale Maintenance: Last release in 2019 raises concerns about:
    • PHP 8.x/9.x Compatibility: May require patches for newer Laravel/Eloquent features (e.g., whereJsonContains, when() clauses).
    • Security: No recent updates could mean unpatched vulnerabilities (though MIT license mitigates some risk).
    • Deprecation Risk: Laravel’s Eloquent evolves; package may lag behind (e.g., no support for Eloquent 9.x features).
  • Overhead for Simple Queries: For APIs with static queries, the package might introduce unnecessary complexity.
  • Testing Burden: Custom rules/conditions require unit tests to ensure correctness, especially for edge cases (e.g., SQL injection via malformed input).

Key Questions

  1. Compatibility:
    • Does the package support Laravel 9.x/10.x and PHP 8.1+? If not, what’s the effort to backport?
    • Are there known conflicts with other query-building packages (e.g., spatie/laravel-query-builder)?
  2. Performance:
    • How does it handle complex nested queries (e.g., has, whereHas)? Could it generate inefficient SQL?
    • Are there N+1 query risks when chaining relationships?
  3. Validation:
    • Does it integrate with Laravel’s Form Request validation, or is it validation-agnostic?
    • How are malformed inputs (e.g., age_more_than=abc) handled?
  4. Alternatives:
    • Would a custom trait or policy-based filtering be simpler for our use case?
    • Are there newer packages (e.g., beberlei/assert, laravel-query-filter) that offer similar functionality with better maintenance?
  5. Monitoring:
    • Can we log generated queries for debugging slow/failing searches?
    • Does it support query caching (e.g., Redis) for repeated parameters?

Integration Approach

Stack Fit

  • Laravel Ecosystem: Perfect for Laravel apps using Eloquent. Works alongside:
    • API Resources (for response shaping).
    • Scout/Algolia (for hybrid search).
    • Laravel Nova (for admin panels with dynamic filtering).
  • Microservices: Useful in BFF (Backend for Frontend) patterns where APIs need dynamic filtering.
  • Non-Laravel PHP: Limited utility outside Laravel due to Eloquent dependency.

Migration Path

  1. Pilot Phase:
    • Start with one high-complexity controller (e.g., /admin/users with 10+ filters).
    • Compare code size and maintainability pre/post-integration.
  2. Incremental Rollout:
    • Replace manual where() chains in controllers with EloquentBuilder rules.
    • Use feature flags to toggle between old/new logic during testing.
  3. Configuration-Driven:
    • Define rules in a centralized config file (e.g., config/eloquent-builder.php) or database table for dynamic updates.
    • Example:
      'users' => [
          'age_more_than' => ['operator' => '>=', 'column' => 'age'],
          'has_published_post' => ['operator' => 'has', 'method' => 'posts'],
      ],
      

Compatibility

  • Eloquent Features:
    • Supports basic where, orWhere, has, and whereHas. May need extensions for:
      • JSON columns (Laravel 8+).
      • Full-text search (e.g., whereRaw).
    • Soft Deletes: Ensure withTrashed() is handled if needed.
  • Request Handling:
    • Works with Laravel’s Request object out of the box. For GraphQL, may need a custom adapter.
  • Testing:
    • Use Pest/PHPUnit to mock EloquentBuilder and test rule logic in isolation.

Sequencing

  1. Phase 1: Core Integration
    • Install package, set up basic rules for CRUD endpoints.
    • Validate against existing query logic (ensure no regressions).
  2. Phase 2: Advanced Features
    • Add support for nested relationships (e.g., author.has_published_books=true).
    • Implement custom operators (e.g., contains, startsWith).
  3. Phase 3: Optimization
    • Add query logging (via Laravel Debugbar or custom middleware).
    • Explore caching for frequent parameter sets.
  4. Phase 4: Monitoring
    • Track query performance (e.g., with Laravel Telescope).
    • Set up alerts for slow queries (e.g., >500ms).

Operational Impact

Maintenance

  • Pros:
    • Reduced Boilerplate: Fewer if-else blocks in controllers → easier to maintain.
    • Centralized Rules: Changes to filtering logic require updates in one place (config/rules).
  • Cons:
    • Package Maintenance: Requires manual patches if Laravel/Eloquent breaks compatibility.
    • Rule Management: Complex rule sets may need documentation or a dedicated admin UI.
  • Mitigations:
    • Fork the repo to backport fixes for Laravel 10.x.
    • Use PHPStan/Psalm to catch type-related issues early.

Support

  • Debugging:
    • Generated SQL: Log queries to identify performance bottlenecks.
    • Rule Validation: Add custom exceptions for invalid rule configurations.
  • Documentation:
    • Create an internal wiki for:
      • Rule syntax examples.
      • Common pitfalls (e.g., SQL injection vectors).
    • Use Swagger/OpenAPI to document available filters for API consumers.
  • Community:
    • Limited upstream support; rely on GitHub issues or fork contributions.

Scaling

  • Performance:
    • Indexing: Ensure database columns used in filters are indexed (e.g., age, gender).
    • Pagination: Pair with Laravel’s paginate() to avoid memory issues.
    • Batch Processing: For large datasets, use chunking or queue jobs.
  • Horizontal Scaling:
    • Stateless by design; scales with Laravel’s queue workers or read replicas.
  • Load Testing:
    • Simulate high-filter-complexity queries to test database limits.

Failure Modes

Failure Scenario Impact Mitigation
Malformed input (e.g., SQLi) Data corruption or leaks Validate inputs via Laravel Requests.
Unindexed columns Slow queries, timeouts Add database indexes; monitor queries.
Package incompatibility Broken queries Fork and maintain locally.
Rule misconfiguration Incorrect filtering Unit tests for all rule sets.
Database connection issues API timeouts Retry logic + circuit breakers.

Ramp-Up

  • Onboarding:
    • Workshop: 1-hour session on:
      • Rule syntax.
      • Debugging generated SQL.
      • Extending for custom use cases.
    • Cheat Sheet: Quick reference for common operators (e.g., =, >=, has).
  • Training:
    • Pair Programming: New devs pair with seniors to implement a filter.
    • Code Reviews: Enforce rule validation in PRs.
  • Adoption:
    • Incentivize: Tie to tech debt reduction metrics (e.g., "Remove 50% of controller if blocks").
    • Phased Rollout: Start with non-critical endpoints.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope