Loading image

Blogs / Programming

Laravel 10.35 Released

Laravel 10.35 Released

  • showkat ali
  • 0 Comments
  • 3356 View

 

Laravel 10.35 Released: New Features and Updates

The Laravel team released v10.35 with a Blade @use directive, a number abbreviation helper, the ability to generate a secret with artisan down, and more. Here is a bit more info about the new features introduced this week:

Here's a breakdown of the new features in Laravel 10.35:

 

1. Blade @use Directive:

This directive allows you to import PHP classes directly into your Blade templates without using raw PHP tags. This makes your code cleaner and more readable.

Benefits:

  • Improved Readability: You can avoid writing raw PHP code within your Blade templates, making them more readable and maintainable.
  • Reduced Clutter: You can import multiple classes at once, reducing the need for repeated @php blocks.
  • Centralized Organization: You can organize your code by importing classes from separate files, promoting better code structure.

Example:

 

{-- Before --}}
@php
use \App\Enums\WidgetStatusEnum as Status;
@endphp
 
{{-- After --}}
@use('App\Enums\WidgetStatusEnum', 'Status')
@use('App\Models\Bar')
 
{{ Status::Foo }}
{{ Bar::first() }}

2. Number Abbreviation:

The Number::abbreviate() method converts large numbers into human-readable formats, like "1M" for 1 million. This improves the display and readability of large numbers in your application.

Benefits:

  • Concise Representation: Large numbers are displayed in a compact and easily understandable format.
  • Enhanced User Experience: Users can easily grasp the magnitude of large numbers without needing to decipher complicated formats.
  • Improved Accessibility: Abbreviated numbers are easier to read for users 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"

3. Secret Generation for Artisan Down:

The artisan down command now accepts the --with-secret option to automatically generate a secret key for bypassing maintenance mode. This simplifies the process and avoids the need to manually define a secret.

Benefits:

  • Simplified Maintenance: You can quickly enable maintenance mode without needing to define a secret key.
  • Enhanced Security: Generated secrets are more secure than manually defined ones, reducing the risk of unauthorized access.
  • Convenience: It saves time and effort compared to manually defining and managing secrets.

Example:

php artisan down --with-secret

4. Conditional Assertions in AssertableJson:

The AssertableJson class now supports the Conditionable trait, allowing you to write conditional assertions within a single chain of assertions. This improves the clarity and conciseness of your test code.

Benefits:

  • More Readable Tests: You can write conditional assertions without needing nested blocks, making your tests more readable and easier to follow.
  • Reduced Code Duplication: You can avoid repeating the same assertion logic within multiple conditions.
  • Improved Test Maintenance: Maintaining your test code becomes easier with a single assertion chain for different conditions.

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'))
    // ...
;

Additional Resources:

 

 

 

 

 

 

 

 

  • Programming
showkat ali Author

showkat ali

Greetings, I'm a passionate full-stack developer and entrepreneur based in Pakistan. I specialize in PHP, Laravel, React.js, Node.js, JavaScript, and Python. I own interviewsolutionshub.com, where I share tech tutorials, tips, and interview questions. I'm a firm believer in hard work and consistency. Welcome to interviewsolutionshub.com, your source for tech insights and career guidance

0 Comments

Post Comment

Recent Blogs

Recent posts form our Blog

[FIXED]  target class [role] does not exist in  laravel 11

[FIXED] target class [role] does not exist in laravel 11

showkat ali
/
Programming

Read More
How to Integrate TinyMCE in Laravel | Latest 2024

How to Integrate TinyMCE in Laravel | Latest 2024

showkat ali
/
Programming

Read More
Using a Mind Map to Brainstorm Ideas and Finding Solutions to Complex Problems

Using a Mind Map to Brainstorm Ideas and Finding Solutions to Complex Problems

Nasir Hussain
/
English

Read More
Polymorphic Relationships in Laravel: A Comprehensive Guide with Example

Polymorphic Relationships in Laravel: A Comprehensive Guide with Example

showkat ali
/
Programming

Read More
Understanding Laravel's whereAny and whereAll: A Tutorial with SQL Examples

Understanding Laravel's whereAny and whereAll: A Tutorial with SQL Examples

showkat ali
/
Programming

Read More
Top 10+ Best Web Frameworks to Learn for a Successful Web Development Career

Top 10+ Best Web Frameworks to Learn for a Successful Web Development Career

showkat ali
/
Programming

Read More