Download the PHP package shammaa/laravel-optimized-queries without Composer

On this page you can find all versions of the php package shammaa/laravel-optimized-queries. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-optimized-queries

Laravel Optimized Queries

Latest Version Total Downloads License

Transform 5-15 Eloquent queries into a single optimized SQL statement using JSON aggregation. Reduce database calls, improve response time, and keep Eloquent's clean syntax.


✨ Features


📦 Installation

Publish configuration (optional):


🚀 Quick Start

1. Add the Trait

2. Write Queries

That's it! The package auto-detects that author is BelongsTo, category is BelongsTo, and comments is HasMany.


📖 Usage Guide

Loading Relations

Counting Relations

Aggregate Subqueries

WHERE Conditions

Conditional Chaining

Build queries dynamically based on conditions:

Scoped Queries

Create optimized queries with pre-applied conditions:

Nested Relations

Searching

Ordering


📄 Pagination & Large Datasets

Pagination

Chunking

Lazy Collections


🌍 Translation Support

Automatic integration with shammaa/laravel-model-translations:


💾 Caching

Cache auto-clears when models are saved or deleted.


🔧 Output Formats


🔧 Retrieval Methods


🕵️ Debugging


🔀 Using the Facade


⚙️ Configuration

Environment Variables

Variable Default Description
OPTIMIZED_QUERIES_CACHE true Enable/disable caching
OPTIMIZED_QUERIES_CACHE_TTL 3600 Default cache TTL (seconds)
OPTIMIZED_QUERIES_LOG false Log generated SQL queries
OPTIMIZED_QUERIES_PERFORMANCE_MONITORING false Enable performance tracking
OPTIMIZED_QUERIES_SAFE_MODE true Fallback to Eloquent on failure
OPTIMIZED_QUERIES_MAX_RELATIONS 0 Max relations per query (0 = unlimited)
OPTIMIZED_QUERIES_TIMEOUT 0 Query timeout in seconds (0 = no limit)

🛡️ Safe Mode

When safe_mode is enabled (default), the package automatically falls back to standard Eloquent if the optimized query encounters any issue:


⚡ Performance

How It Works

Traditional Eloquent eager loading executes one query per relation:

This package combines everything into a single query using JSON subqueries:

Real Numbers

Metric Traditional Optimized Improvement
SQL Queries 4-15 1 -93%
Response Time 150-400ms 25-60ms 5-10x faster
Memory Usage High Lower ~40% less
Database Connections Multiple Single -93%

Best Practices

🏗️ Large-Scale Sites (E-Commerce, High Traffic)

For large datasets (100k+ records, 8+ relations), enable query splitting and timeout protection:

How query splitting works:

Why this matters:


🔍 When to Use

✅ Perfect For

⚠️ Consider Standard Eloquent For


🤝 Real-World Example: Homepage

Result: 3 queries total instead of 15-20+. With caching: 0 queries after first visit.


🐛 Troubleshooting

JSON Functions Not Supported

Your database must support JSON functions:

Query Returns Empty Relations

Make sure your model has the relation method defined:

Slow Queries

  1. Add database indexes on foreign keys
  2. Use ->select() to limit columns
  3. Use ->paginate() or ->limit()
  4. Enable caching with ->cache(3600)

Cache Not Clearing

Cache auto-clears on model saved and deleted events. For manual clearing:

Laravel Octane / Long-Running Processes

The in-memory request cache clears automatically when models are saved/deleted. To clear manually:


📝 Requirements


📄 License

MIT License. See LICENSE file.


👤 Author

Shadi Shammaa — [email protected]


⭐ Support

If this package saved you time, please give it a star on GitHub! Every star helps the package reach more developers.


All versions of laravel-optimized-queries with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
illuminate/support Version ^9.0|^10.0|^11.0|^12.0
illuminate/database Version ^9.0|^10.0|^11.0|^12.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package shammaa/laravel-optimized-queries contains the following files

Loading the files please wait ...