Laravel 10.34 Released


This week, the Laravel team released v10.34, adding a missing() method that applies to route groups, an alias for the new Number class, an extensions validation rule, and more. Here is a bit more info about the new features introduced this week:
Allow Multiple Types in Collection's ensure() method
Ash Allen contributed an update to the Collection ensure() method that allows you to pass multiple types instead of only allowing one type:
collect([new User(), new Contact(), new Contact()])
->ensure([User::class, Contact::class]);

Allow missing() on Route groups
Ronald Edelschaap contributed the ability to add a missing() callback for the routes on a group:
// Before
Route::prefix('locations')
->group(function() {
Route::get('{location}', [LocationsController::class, 'show'])
->missing(fn() => ['success' => false, 'message' => 'The requested location does not exist']);
Route::put('{location}', [LocationsController::class, 'update'])
->missing(fn() => ['success' => false, 'message' => 'The requested location does not exist']);
Route::delete('{location}', [LocationsController::class, 'destroy'])
->missing(fn() => ['success' => false, 'message' => 'The requested location does not exist']);
});

// After
Route::prefix('locations')
->missing(fn() => ['success' => false, 'message' => 'The requested location does not exist'])
->group(function() {
Route::get('{location}', [LocationsController::class, 'show']);
Route::put('{location}', [LocationsController::class, 'update']);
Route::delete('{location}', [LocationsController::class, 'destroy']);
});

Extensions validation rule
@eusonlito contributed a file extensions validation rule that you can use in combination with the mimes validation rule:
['file', 'mimes:jpg,jpeg,png', 'extensions:jpg,png']

The extensions rule was added to the Validation documentation, which notes that the extensions rule should be used in tandem with validating the mime type via the mimes rule.
See Pull Request #49082 for more details.
Alias Number class
Jamie York contributed aliasing the Number Utility Class for quick use in Blade templates without needing to import the full namespace:
Percentage: {{ Number::percentage(50) }}

Conditionable added to TestResponse
Noboru Shiroiwa contributed adding the Conditionable trait to the TestResponse class, which you can use when asserting the response:
test('name', function ($attributes) {
$user = User::factory()->create($attributes);

$response = $this
->actingAs($user)
->get('/');

$response
->assertOk()
->when($attributes['gender'] === 1, fn () => $response->assertSee('Hello boys!'))
->when($attributes['gender'] === 2, fn () => $response->assertSee('Hello girls!'));
})->with([
'boy' => [
[
'name' => 'Michael',
'gender' => 1,
],
],
'girl' => [
[
'name' => 'Susan',
'gender' => 2,
],
],
]);

Release notes
You can see the complete list of new features and updates below and the diff between 10.33.0 and 10.34.0 on GitHub. The following release notes are directly from the changelog:
v10.34.0

The post Laravel 10.34 Released appeared first on Laravel News.
Join the Laravel Newsletter to get Laravel articles like this directly in your inbox.