The Laravel team tagged v12.1.0—the first minor release of Laravel 12—which includes a context scope method, an Arr::partition() method, a getRawSql() method on query exception instances, and more.
New Array Partition Method
Liam Duckett contributed the partition
method to the Array helper, which allows using existing partition logic without having to reach for collections:
$numbers = [0, 1, 2, 3, 4, 5]; // Using collections[$evens, $odds] = collect($numbers)->partition(fn(int $number) => $number % 2 === 0); // Using the Arr::partition() method[$evens, $odds] = Arr::partition($numbers, fn(int $number) => $number % 2 === 0);
This method partitions the array into two arrays using the provided callback.
Added a getRawSql() Method to Query Exceptions
@erickcomp contributed a getRawSql()
method to the QueryException
class, which returns the raw SQL representation of the query with embedded bindings. You could use this to report any problematic query errors:
->withExceptions(function (Exceptions $exceptions) { $exceptions->report(function (QueryException $e) { // ... MyErrorServiceFacade::report('Error executing SQL: ', $e->getRawSql()); });})
Context Scope Method
Luke Kuzmish contributed a Context::scope()
method that can include context for the duration of a function call and then restore the context to what it was before the call:
// BeforeContext::add('event_id', $event->id); try { $this->innerHandle($event);} finally { Context::forget(['event_id', 'sns_message_id']);} // AfterContext::scope( fn () => $this->innerHandle($event), ['event_id' => $event->id]);
You can learn more about the Context::scope()
method in the documentation.
PendingCommand Class is Now Tappable
Kevin Bui added the Tappable
trait to the testing PendingCommand
class, which allows you to handle assertions all in one go:
$this->artisan('orders:refunding', ['--ids' => 1]) ->expectsOutput('Start Refunding...') ->tap(function ($command) { // ... $command->expectsOutput('...'); });
See Pull Request #54801 for the complete example.
Release notes
You can see the complete list of new features and updates below and the diff between 12.0.0 and 12.1.0 on GitHub. The following release notes are directly from the changelog:
v12.1.0
- [12.x] Test Improvements by @crynobone in https://github.com/laravel/framework/pull/54782
- [12.x] Fix incorrect typehints in
BuildsWhereDateClauses
traits by @mohprilaksono in https://github.com/laravel/framework/pull/54784 - [12.x] Improve queries readablility by @hafezdivandari in https://github.com/laravel/framework/pull/54791
- [12.x] Enhance eventStream to Support Custom Events and Start Messages by @devhammed in https://github.com/laravel/framework/pull/54776
- [12.x] Make the PendingCommand class tappable. by @kevinb1989 in https://github.com/laravel/framework/pull/54801
- [12.x] Add missing union type in event stream docblock by @devhammed in https://github.com/laravel/framework/pull/54800
- Change return types of
paginage()
methods to\Illuminate\Pagination\LengthAwarePaginator
by @carestad in https://github.com/laravel/framework/pull/54826 - [12.x] Check if internal
Hasher::verifyConfiguration()
method exists on driver before forwarding call by @rodrigopedra in https://github.com/laravel/framework/pull/54833 - [11.x] Fix using
AsStringable
cast on Notifiable's key by @crynobone in https://github.com/laravel/framework/pull/54818 - Add Tests for Handling Null Primary Keys and Special Values in Unique Validation Rule by @alikhosravidev in https://github.com/laravel/framework/pull/54823
- Improve docblock for with() method to clarify it adds to existing eag… by @igorlealantunes in https://github.com/laravel/framework/pull/54838
- [12.x] Fix dropping schema-qualified prefixed tables by @hafezdivandari in https://github.com/laravel/framework/pull/54834
- [12.x] Add
Context::scope()
by @cosmastech in https://github.com/laravel/framework/pull/54799 - Allow Http requests to be recorded without requests being faked by @kemp in https://github.com/laravel/framework/pull/54850
- [12.x] Adds a new method "getRawSql" (with embedded bindings) to the QueryException class by @erickcomp in https://github.com/laravel/framework/pull/54849
- Update Inspiring.php by @ju-gow in https://github.com/laravel/framework/pull/54846
- [12.x] Correct use of named argument in
Date
facade and fix a return type. by @lmottasin in https://github.com/laravel/framework/pull/54847 - Add additional tests for Rule::array validation scenarios by @alikhosravidev in https://github.com/laravel/framework/pull/54844
- [12.x] Remove return statement by @mohprilaksono in https://github.com/laravel/framework/pull/54842
- Fix typos by @co63oc in https://github.com/laravel/framework/pull/54839
- [12.x] Do not loop through middleware when excluded is empty by @cosmastech in https://github.com/laravel/framework/pull/54837
- Add test for Arr::reject method in Illuminate Support by @mohammadrasoulasghari in https://github.com/laravel/framework/pull/54863
- [12.x] Feature: Array partition by @liamduckett in https://github.com/laravel/framework/pull/54859
- [12.x] Introduce
ContextLogProcessor
by @cosmastech in https://github.com/laravel/framework/pull/54851