Laravel 10.35 Released

Laravel 10.35 Released

The Laravel team has published version 10.35 of the popular PHP web framework. This Laravel new release includes various bug fixes and enhancements. Here are some of the highlights from this update.

Blade @use Directive:

The @use directive allows for the importation of PHP classes into Blade templates, eliminating the requirement for raw PHP tags. This helps to improve code cleanliness and readability.

Advantages:

  1. Enhanced Readability: By eliminating the need for raw PHP code in Blade templates, the code becomes more legible and maintainable.
  2. Minimized Clutter: Importing many classes concurrently removes the need for repeating @php sections, resulting in a more streamlined and simple codebase.
  3. Centralized Organization: The ability to import classes from several files allows for a more ordered code structure, which contributes to better overall code organization.

Example:

{{-- Before --}}
@php
    use \App\Enums\WidgetStatusEnum as Status;
@endphp

{{-- After --}}
@use('App\Enums\WidgetStatusEnum', 'Status')
@use('App\Models\Bar')

{{ Status::Foo }}
{{ Bar::first() }}
Blade

Number Abbreviation:

The Number::abbreviate() method reduces large numbers to short, human-readable formats, such as “1M” for one million. This improves the presentation and comprehension of large numerical figures within your application.

Advantages:

  1. Concise Representation: Display enormous figures in a compact and easily understandable style.
  2. Enhanced User Experience: Help users understand the size of enormous numbers without having to decode complex numerical forms.
  3. Improved Accessibility: Abbreviated numbers improve reading, particularly for people with visual impairments.

Example:

Number::abbreviate(1_000_000); // "1M"
Number::abbreviate(100_001);   // "100K"
Number::abbreviate(99_999);    // "100K"
Number::abbreviate(99_499);    // "99K"
PHP

Secret Generation for Artisan Down:

The artisan down command adds the –with-secret option, which simplifies the activation of maintenance mode by automatically producing a secure key. This eliminates the manual requirement for specifying a secret and provides various benefits.

Advantages:

  1. Simplified Maintenance: The activation of maintenance mode is accelerated, eliminating the need to manually enter a secret key.
  2. Enhanced Security: Automatically generated secrets improve security by decreasing the likelihood of unauthorized access as compared to manually set keys.
  3. Convenience: This feature saves time and effort by providing a more convenient alternative to manually defining and managing secrets.

Example:

php artisan down --with-secret
Bash

Conditional Assertions in AssertableJson:

The AssertableJson class has been improved to include the conditionable trait, which allows for the insertion of conditional assertions in a unified chain. This feature helps to create better and more succinct test code.

Advantages:

  1. More Readable Tests: Conditional assertions can be expressed without using nested blocks, which improves the readability and comprehension of your tests.
  2. Reduced Code Duplication: Eliminate the recurrence of similar assertion logic across multiple situations, which improves code performance.
  3. Improved Test Maintenance: A streamlined assertion chain that addresses various circumstances simplifies test code maintenance.

Example:

// Before
$response->assertJson(function (AssertableJson $json) use ($condition) {
    $json->has('data');
 
    if ($condition) {
        $json->has('meta');
    }
 
   $json->etc();
});
 
// After
$response
    ->assertJson(fn (AssertableJson $json) => $json->has('data'))
    ->when($condition, fn (AssertableJson $json) => $json->has('meta'))
    // ...
;
PHP

Release notes

Check out the list of new features and improvements below, as well as the differences between 10.34.0 and 10.35.0 on GitHub. The release notes below are directly from the changelog.

v10.35.0

FAQ

What is Laravel 10.35?

Laravel 10.35 is the most recent version of the Laravel PHP framework, which includes new features, enhancements, and bug fixes to improve the development experience.

How often does Laravel release updates?

Laravel has a regular release cycle, with updates issued every few weeks or months to give developers with the most recent features and fixes.

Can I upgrade to Laravel 10.35 from a previous version?

Yes, you can upgrade to Laravel 10.35 from a prior version by following the upgrade instructions in the official Laravel documentation.

How can I install or update to Laravel 10.35 using Composer?

To install or upgrade Laravel 10.35, use Composer with the following command: composer create-project --prefer-dist laravel/laravel myproject (change myproject with your project’s name).

Can I use Laravel 10.35 for new projects, or is it recommended for existing projects only?

Laravel 10.35 is ideal for both new and existing projects. It is recommended to use the most recent version for new projects in order to take advantage of the most recent features and improvements.

Have questions about this blog? Contact us for assistance!