Posts

Since 2024
Rule::array() and whereJsonOverlaps() for MySQL in Laravel 11.7
Rule::array() and whereJsonOverlaps() for MySQL in Laravel 11.7

This week, the Laravel team released v11.7, with a Rule::array() validation method, a whereJsonOverlaps() method for MySQL, a Slack OpenID provider for Laravel Socialite, and more. Introduce the Rule::array() Method Jakub Potocký contributed the Rule::array() method used to validate multiple array keys using the array validation rule. This method enables using this rule with arrays and collections without having the concatenate dynamic values: use Illuminate\Validation\Rule; // Before ['array:' . MyBackedEnum::VALUE->value . ',' . MyBackedEnum::VALUE_2->value]; // After examples Rule::array('key_1', 'key_2', 'key_3'); Rule::array(['key_1', 'key_2', 'key_3']); Rule::array(collect(['key_1', 'key_2', 'key_3'])); Rule::array([UnitEnum::key_1, UnitEnum::key_2, UnitEnum::key_3]); Rule::array([BackedEnum::key_1, BackedEnum::key_2, BackedEnum::key_3]); See Pull Request #51250 for full details. Stringable Support in blank() and filled() Helpers Stefan R. contributed support for Stringable values in the blank() and filled() helpers: // true filled(str('FooBar ')); // true blank(str(' ')); Add "whereJsonOverlaps()" for MySQL Benjamin Ayles contributed support for MySQL's json_overlaps feature that compares two JSON documents: User::whereJsonOverlaps('languages', ['en', 'fr'])->exists(); User::whereJsonDoesntOverlap('languages', ['en', 'fr'])->exists(); See Pull Request #51288 for more details and discussion. Add PasswordResetLinkSent Event Matt Jones contributed a new event called PasswordResetLinkSent which fires when a password reset link is sent. See Pull Request #51253 for more details. Laravel Socialite Provider for Slack OpenID Maarten Paauw contributed a separate Slack OpenID provider for Laravel Socialite. See Pull Request #704 for details and links to the Slack documentation. Release notes You can see the complete list of new features and updates below and the diff between 11.6.0 and 11.7.0 on GitHub. The following release notes are directly from the changelog: v11.7.0 [11.x] Fix SesV2Transport to use correct EmailTags argument by @Tietew in https://github.com/laravel/framework/pull/51265 [11.x] Add Databases nightly workflow by @Jubeki in https://github.com/laravel/framework/pull/51218 [11.x] update "min" and "max" rule comments by @browner12 in https://github.com/laravel/framework/pull/51274 [11.x] Fix namespace and improvement PSR in ClassMakeCommandTest.php by @saMahmoudzadeh in https://github.com/laravel/framework/pull/51280 [11.x] improvement test coverage for view components. by @saMahmoudzadeh in https://github.com/laravel/framework/pull/51271 [11.x] Introduce method Rule::array() by @Jacobs63 in https://github.com/laravel/framework/pull/51250 [11.x] Fix docblock for collection pluck methods by @SanderMuller in https://github.com/laravel/framework/pull/51295 [11.x] Add tests for handling non-baked enum and empty string requests by @hrant1020 in https://github.com/laravel/framework/pull/51289 blank and filled now support stringable by @lava83 in https://github.com/laravel/framework/pull/51300 [11.x] Fix ratio validation for high ratio images by @ahmedbally in https://github.com/laravel/framework/pull/51296 [11.x] Add int|float support to e method by @trippo in https://github.com/laravel/framework/pull/51314 [11.x] Add release notes by @driesvints in https://github.com/laravel/framework/pull/51310 [11.x] Stringable is also an interface of symfony by @lava83 in https://github.com/laravel/framework/pull/51309 [11.x] Add some tests and improvement test coverage for Str::camel by @saMahmoudzadeh in https://github.com/laravel/framework/pull/51308 [11.x] Using the ?? Operator (Null Coalescing Operator) by @saMahmoudzadeh in https://github.com/laravel/framework/pull/51305 [11.x] Add ability to override the default loading cached Routes for application by @ahmedabdel3al in https://github.com/laravel/framework/pull/51292 [11.x] Add ->whereJsonOverlaps() for mysql by @parkourben99 in https://github.com/laravel/framework/pull/51288 [11.x] Add InteractsWithInput methods to ValidatedInput by @aydinfatih in https://github.com/laravel/framework/pull/51316 [11.x] Adding PasswordResetLinkSent event by @Muffinman in https://github.com/laravel/framework/pull/51253 The post Rule::array() and whereJsonOverlaps() for MySQL in Laravel 11.7 appeared first on Laravel News. Join the Laravel Newsletter to get Laravel articles like this directly in your inbox.

Optimize Your Eloquent Queries with AI
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: A configurable slow threshold Configurable AI models like Chat GPT-4 Disable AI and only log slow queries Configurable prompt for AI Disable slow query analysis 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 Laravel articles like this directly in your inbox.