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
- [10.x] Fix
hex_color
validation rule by @apih in https://github.com/laravel/framework/pull/49070 - [10.x] Prevent passing null to base64_decode in Encrypter by @robtesch in https://github.com/laravel/framework/pull/49071
- [10.x] Alias Number class by @ziadoz in https://github.com/laravel/framework/pull/49073
- [10.x] Added File Validation
extensions
by @eusonlito in https://github.com/laravel/framework/pull/49082 - [10.x] Add @throws in doc-blocks by @imanghafoori1 in https://github.com/laravel/framework/pull/49091
- [10.x] Update docblocks for consistency by @dwightwatson in https://github.com/laravel/framework/pull/49092
- [10.x] Throw exception when trying to initiate
Collection
usingWeakMap
by @crynobone in https://github.com/laravel/framework/pull/49095 - [10.x] Only stage committed transactions by @hansnn in https://github.com/laravel/framework/pull/49093
- Better transaction manager object design by @taylorotwell in https://github.com/laravel/framework/pull/49103
- [10.x] use php 8.3
mb_str_pad()
forStr::pad*
by @amacado in https://github.com/laravel/framework/pull/49108 - [10.x] Add Conditionable to TestResponse by @nshiro in https://github.com/laravel/framework/pull/49112
- [10.x] Allow multiple types in Collection's
ensure
method by @ash-jc-allen in https://github.com/laravel/framework/pull/49127 - [10.x] Fix middleware "SetCacheHeaders" with download responses by @clementbirkle in https://github.com/laravel/framework/pull/49138
- [10.x][Cache] Fix handling of
false
values in apc by @simivar in https://github.com/laravel/framework/pull/49145 - [10.x] Reset numeric rules after each attribute's validation by @apih in https://github.com/laravel/framework/pull/49142
- [10.x] Extract dirty getter for
performUpdate
by @taka-oyama in https://github.com/laravel/framework/pull/49141 - [10.x]
ensure
: Resolve$itemType
outside the closure by @lucasmichot in https://github.com/laravel/framework/pull/49137 - Allow "missing" method to be used on route groups by @redelschaap in https://github.com/laravel/framework/pull/49144
- [10.x] Get tables and views info by @hafezdivandari in https://github.com/laravel/framework/pull/49020
- [10.x] Fix
MorphTo::associate()
PHPDoc parameter by @devfrey in https://github.com/laravel/framework/pull/49162 - [10.x] Make test error messages more multi-byte readable by @nshiro in https://github.com/laravel/framework/pull/49160
- [10.x] Generate a unique hash for anonymous components by @billyonecan in https://github.com/laravel/framework/pull/49156
- [10.x] Improves output when using
php artisan about --json
by @crynobone in https://github.com/laravel/framework/pull/49154 - [10.x] Make fake instance inherit from
Vite
when usingwithoutVite()
by @orkhanahmadov in https://github.com/laravel/framework/pull/49150
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.