Optimize Your Eloquent Queries with AI

The Laravel Slower package is designed for Laravel developers who want to enhance the performance of their applications. This package identifies slow queries and suggests optimizations such as indexing and other improvements.

Depending on how you configure your application's scheduler, you could run the following commands each day to analyze and clean up old records:

php artisan slower:clean /*{days=15}  Delete records older than 15 days.*/
php artisan slower:analyze /*Analyze the records where is_analyzed=false*/

Recommendations created with the slower:analyze command are stored in the database table created by this package, which you can review after AI analysis is completed. As part of the AI analysis, this package's main features include:

The README includes an example analysis to help you visualize what you can expect with this package:

/*
select count(*) as aggregate
from "product_prices"
where "product_id" = '1'
  and "price" = '0'
  and "discount_total" > '0'
*/

dd($model->recommendation);

/*
Indexing: Effective database indexing can significantly speed up query performance. For your query, consider adding a combined (composite)
index on product_id, price, and discount_total. This index would work well
because the where clause covers all these columns.
*/

/*
CREATE INDEX idx_product_prices
ON product_prices (product_id, price, discount_total);
*/

You can learn more about this package, get full installation instructions, and view the source code on GitHub.


The post Optimize Your Eloquent Queries with AI appeared first on Laravel News.

Join the Laravel Newsletter to get all the latest Laravel articles like this directly in your inbox.