Newslurp

<< Stories

PHP 8.4 is released 🚀, Http::preventStrayRequests() 💡, Postgres and MySQL, the main differences ⚖️, Laravel Custom Query Builders Over Scopes 🔍

The Laralist <hello@thelaralist.com>

November 24, 11:29 am

PHP 8.4 is released 🚀, Http::preventStrayRequests() 💡, Postgres and MySQL, the main differences ⚖️, Laravel Custom Query Builders Over Scopes 🔍
PHP 8.4 introduces major features like Property Hooks and Asymmetric Visibility, enhancing class property management. It also offers Lazy Objects, HTML5-compliant DOM parsing, and driver-specific PDO subclasses, improving overall performance and security.
The Laralist
24th of November, 2024
🧱
Laravel

Explore the benefits and drawbacks of using query scopes in Laravel. Learn how custom query builders can enhance code organization, improve autocompletion, and streamline complex queries.

Discover advanced string pattern replacement in Laravel using Str::replaceMatches. Learn both simple and complex closure-based transformations, enhancing tasks like phone formatting and keyword highlighting.

Learn to dynamically configure Laravel components with the new build() methods for Mail, DB, and Cache, allowing flexibility by defining configurations on the fly.

This release introduces the createQuietly() method to save new models without triggering events. The Request::enums() is added to easily retrieve arrays of enums from incoming requests, enhancing type-safe data handling. Factories now include the disableRelationships() method to prevent unnecessary relationship creation, ideal for unit testing.

💡
Tip of the Week

When testing, Laravel’s Http::preventStrayRequests() ensures that every HTTP request in your tests is either explicitly faked. This prevents accidental real API calls during testing, ensuring your suite remains fast and controlled.

Http::preventStrayRequests();

Http::fake([
    'example.dev/*' => Http::response(['data' => 'something']),
]);

// Throws an exception because no fake is defined for this request
$response = Http::get('https://notfaked.dev/resource');
🐘
PHP

PHP 8.4 introduces major features like Property Hooks and Asymmetric Visibility, enhancing class property management. It also offers Lazy Objects, HTML5-compliant DOM parsing, and driver-specific PDO subclasses, improving overall performance and security.

PIE (PHP Installer for Extensions) has entered its pre-release phase, offering a modern approach to managing PHP extensions. It serves as a flexible alternative to PECL, treating extensions as first-class citizens. With PIE, extensions are distributed via Packagist, similar to regular PHP packages, though maintainers need to make adjustments to support this new extension manager.

This PHP RFC outlines a structured policy for referencing and using third-party PHP code, balancing non-endorsement with practical needs. It proposes clear inclusion criteria, such as being a de facto standard or having a stable release, as well as exclusion criteria and pre-approved libraries like Composer and xDebug. Finally, it provides guidelines for conflict resolution. Full details can be found in the PR.

📦
Package of the Week

The muddle package helps protect email addresses and strings in PHP and Laravel applications from bots. It provides multiple obfuscation strategies for both clickable and non-clickable emails, allowing you to safeguard sensitive information like your email or your users’ emails from spam bots.

Misc

A detailed comparison of Postgres and MySQL, focusing on differences in indexing, data storage, updates, MVCC implementation, and query costs.

State machines can simplify complex logic by defining states and transitions clearly. This article explores their implementation in PHP applications, covering practical use cases and providing a step-by-step guide to better organize application workflows.

We value your thoughts and feedback. Feel free to hit reply and share your ideas with us.
If you find our content helpful, please consider forwarding it to your friends and colleagues.
Thank you for reading,
Mario & Javi
If you prefer not to receive future editions of The Laralist, please unsubscribe.