Top 10+ Best Web Frameworks to Learn for a Successful Web Development Career
Read More
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:
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:
@php
blocks.Example:
{-- Before --}}
@php
use \App\Enums\WidgetStatusEnum as Status;
@endphp
{{-- After --}}
@use('App\Enums\WidgetStatusEnum', 'Status')
@use('App\Models\Bar')
{{ Status::Foo }}
{{ Bar::first() }}
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:
Example:
Number::abbreviate(1_000_000); // "1M"
Number::abbreviate(100_001); // "100K"
Number::abbreviate(99_999); // "100K"
Number::abbreviate(99_499); // "99K"
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:
Example:
php artisan down --with-secret
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:
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:
Recent posts form our Blog
0 Comments
Like 0