The Laravel team released v11.20 this week, including a new collection method, a deduplicate string method, the ability to use Enums with AssertableJson, and more.
Add collapseWithKeys to Collection
Jason McCreary contributed a collapseWithKeys() method to the IlluminateSupportCollection class that collapses nested arrays while preserving their keys:
$c = collect([[1 => ‘a’], [3 => ‘c’], [2 => ‘b’]]);
$c->collapseWithKeys();
/*
[
1 => “a”,
3 => “c”,
2 => “b”,
]
*/
Add deduplicate to strings
Jason McCreary contributed a deduplicate string helper that replaces consecutive occurrences of a character with a character:
Str::deduplicate(‘random double spaces’); // ‘random double spaces’
Str::deduplicate(‘/some//odd/path//’, ‘/’); // ‘/some/odd/path/’
(string) str(‘zondaaaa’)->deduplicate(‘a’); // ‘zonda’
Allow Custom View Path When Making Components
Andrew Brown contributed the ability to define a –path flag when you need to create the view path in a custom file location:
php artisan make:component Foo –path custom/path
By default, the make:component command will continue to use the resources/views/components folder.
Introduce a MixFileNotFoundException Exception Class
Ihor Vereshchynskyi contributed a new MixFileNotFoundException class to handle missing Mix files. This exception provides a more precise error-handling mechanism when this exception gets thrown.
Allow enums to be passed to AssertableJson where methods
Patrick O’Meara contributed the ability to use Enums while using where* methods with AssertableJson instances:
// Before
fn (AssertableJson $json) => $json->where(‘role’, UserRole::Developer->value)
// After
fn (AssertableJson $json) => $json->where(‘role’, UserRole::Developer)
Prompt to Create a Markdown Template When Making Notifications
Christoph Rumpel updated the make:notification command to prompt for creating an optional markdown view when you don’t provide any initial input:
php artisan make:notification
You will get the following prompts to select a markdown view for your notification class:
Markdown view prompts in the make:notification command
Add stackContains() and hiddenStackContains() Methods to Context Stacks
@lessevv contributed the ability to check if a value (or hidden value) is contained in a context stack. Here are a few examples from Pull Request #52346:
// Normal
Context::push(‘foo’, ‘bar’, ‘lorem’);
Context::stackContains(‘foo’, ‘bar’); // true
Context::stackContains(‘foo’, ‘lorem’); // true
Context::stackContains(‘foo’, ‘doesNotExist’); // false
// Hidden
Context::pushHidden(‘foo’, ‘bar’, ‘lorem’);
Context::hiddenStackContains(‘foo’, ‘bar’); // true
Context::hiddenStackContains(‘foo’, ‘lorem’); // true
Context::hiddenStackContains(‘foo’, ‘doesNotExist’); // false
Inverse Fake Queue Assertion Methods
Günther Debrauwer contributed assertNotDeleted, assertNotFailed, and assertNotReleased assertions to the queue that you can use to assert the inverse of these methods:
use AppJobsProcessPodcast;
Â
$job = (new ProcessPodcast)->withFakeQueueInteractions();
Â
$job->handle();
$job->assertNotDeleted();
$job->assertNotFailed();
$job->assertNotReleased();
Make Facade::isFake() Public
Caleb White contributed an update to the isFake() method, making the visibility public:
use IlluminateSupportFacadesBus;
Bus::isFake(); // false
Bus::fake();
Bus::isFake(); // true
Release notes
You can see the complete list of new features and updates below and the diff between 11.19.0 and 11.20.0 on GitHub. The following release notes are directly from the changelog:
v11.20.0
Update testcase for whereNone method by @einar-hansen in https://github.com/laravel/framework/pull/52351
Improve Lock->block method by @RedmarBakker in https://github.com/laravel/framework/pull/52349
[11.x] Use correct pluralization rules in trans_choice for fallback strings by @stefanvdlugt in https://github.com/laravel/framework/pull/52343
[11.x] Replace dead link in Security Policy by @Jubeki in https://github.com/laravel/framework/pull/52338
Add compatible query type to Model::resolveRouteBindingQuery by @sebj54 in https://github.com/laravel/framework/pull/52339
[10.x] Fix Factory::afterCreating callable argument type by @villfa in https://github.com/laravel/framework/pull/52335
[11.x] Remove undefined class PreventRequestsDuringMaintenance by @seriquynh in https://github.com/laravel/framework/pull/52322
[11.x] Add middleware before sending request and dispatching events by @eduance in https://github.com/laravel/framework/pull/52323
Add collapseWithKeys to Collection by @jasonmccreary in https://github.com/laravel/framework/pull/52347
[11.x] Inverse Fake Queue Interactions: assertNotDeleted, assertNotFailed, and assertNotReleased by @gdebrauwer in https://github.com/laravel/framework/pull/52320
Add deduplicate to strings by @jasonmccreary in https://github.com/laravel/framework/pull/52350
[11.x] feat: make Facade::isFake() public by @calebdw in https://github.com/laravel/framework/pull/52357
[11.x] Ask about markdown template for notification command with no initial input by @christophrumpel in https://github.com/laravel/framework/pull/52355
[11.x] allow custom view path when making components by @browner12 in https://github.com/laravel/framework/pull/52219
[11.x] chore: update to PHPStan Level 1 by @calebdw in https://github.com/laravel/framework/pull/51956
[11.x] Support passing default as named parameter in whenLoaded, whenAggregated, whenCounted by @hn-seoai in https://github.com/laravel/framework/pull/51342
Declare exceptions unreportable using the ShouldntReport interface by @chrispage1 in https://github.com/laravel/framework/pull/52337
[11.x] Enable extension of connection inspection methods by @GromNaN in https://github.com/laravel/framework/pull/52231
[11.x] Add whenExistsLoaded method to conditionally include relationship existence attribute by @CodeWithKyrian in https://github.com/laravel/framework/pull/52295
[11.x] Add in() and inHidden() functions to Context Stacks by @lessevv in https://github.com/laravel/framework/pull/52346
[11.x] Use Command::fail() method for single error messages by @seriquynh in https://github.com/laravel/framework/pull/52387
[11.x] Rework Context::stackContains with Closures. by @timacdonald in https://github.com/laravel/framework/pull/52381
[11.x] Allow enums to be passed to AssertableJson where methods by @patrickomeara in https://github.com/laravel/framework/pull/52360
[11.x] Made list validation rule as array for “size rules” in validation messages by @siarheipashkevich in https://github.com/laravel/framework/pull/52385
[11.x] Add contextual attributes to resolve drivers by @ziadoz in https://github.com/laravel/framework/pull/52265
[11.x] Fix docblocks for where(All|Any|None) query methods by @einar-hansen in https://github.com/laravel/framework/pull/52388
[10.x] backport #52204 by @calebdw in https://github.com/laravel/framework/pull/52389
[11.x] Fix Http Client Pool requests that have no response by @andrewbroberg in https://github.com/laravel/framework/pull/52393
[11.x] Introduce MixFileNotFoundException for handling missing Mix files by @Ex10Dios in https://github.com/laravel/framework/pull/52400
[10.x] In MySQL, harvest last insert ID immediately after query is executed by @piurafunk in https://github.com/laravel/framework/pull/52390
The post A New String Helper, Assert Enums in AssertableJson, and more in Laravel 11.20 appeared first on Laravel News.
Join the Laravel Newsletter to get all the latest Laravel articles like this directly in your inbox.
Source: Read MoreÂ