{"repo":"rgalstyan/laravel-aggregated-queries","free":true,"listed":false,"github":"https://github.com/rgalstyan/laravel-aggregated-queries","clone":"git clone https://github.com/rgalstyan/laravel-aggregated-queries.git","description":"Optimize Laravel queries using SQL JSON aggregation - reduce multiple relation queries to a single SQL statement","language":"PHP","stars":10,"topics":["aggregate-functions","database","eloquent","laravel","laravel-package","mysql","optimization","performance","postgresql","query-builder"],"license":"MIT","category":"databases-storage","readme_excerpt":"Laravel Aggregated Queries Reduce multi-relation Eloquent queries to a single optimized SQL statement using JSON aggregation. Perfect for read-heavy APIs, dashboards, and admin panels where traditional eager loading generates too many queries. --- The Problem Even with proper eager loading, Laravel generates one query per relation: Produces 4 separate queries: Complex pages easily generate 5–15 queries , increasing: - Database round-trips - Response time - Memory usage - Server load --- The Solution Transform multiple queries into one optimized SQL statement using JSON aggregation: Generates a single query: Result: - ✅ 1 database round-trip instead of 4 - ✅ Up to 6x faster response time - ✅ 90%+ less memory usage - ✅ Consistent array output --- Performance Real benchmark on 2,000 partners with 4 relations (50 records fetched): Method Time Memory Queries -------- ------ -------- --------- Traditional Eloquent 27.44ms 2.06MB 5 Aggregated Query 4.41ms 0.18MB 1 Improvement ⚡ 83.9% faster 💾 91.3% less 🔢 80% fewer At scale (10,000 API requests/day): - 40,000 fewer database queries - 3.8 minutes saved in response time - 18.6GB less memory usage --- Requirements Component Version ----------- ------------------------- PHP ^8.2 Laravel ^10.0 \\ ^11.0 \\ ^12.0 MySQL ^8.0 PostgreSQL ^12.0 --- Installation --- Quick Start 1. Add trait to your model 2. Query with aggregation 3. Use the data Output structure (guaranteed): --- Advanced Usage Reuse existing queries Already have complex query ","default_branch":null,"files":null,"tree":[],"storefront":"/r/rgalstyan","claimed":false,"request_supported":{"post":"https://gitbuyer.com/r/rgalstyan/laravel-aggregated-queries/request-supported","requests":0},"note":"indexed from public GitHub; nothing is for sale on this page. Clone it from GitHub. Paid listings live at /search."}