Laravel 9.7 Released


April 6th, 2022

Laravel 9.7 Released

The Laravel team released Laravel v9.7.0 with a whereIn() route parameter constraint method, a Str::squish() helper, JSON path query enhancements, and more:

Query Builder whereBelongsTo() Accepts Collections

Erik Gaal contributed the ability to pass a collection to the whereBelongsTo() method in a query builder:

// Previously
// ...
// Or...
$query->whereIn('category_id', $categories->modelKeys());
// >=9.7 can use collections:
$query->whereBelongsTo($categories, 'category');

Database Queries Containing Json Paths Support Array Index Braces

Derek MacDonald contributed support for array index braces in database queries containing JSON paths:

->where('column->json_option[0]', 'foo')
->update(['column->json_option[0]', => 'bar']);

See Pull Request #41767 for further details and related PRs/issues.

Routing Event Fires Before Route Matched

Tim Roberson contributed a Routing event that fires before the router attempts to find a matching route. This event allows developers to access the request immediately before routing:

use Illuminate\Routing\Events\Routing;
Event::listen(function (Routing $event) {
// ...

Route whereIn() Parameter Constraint Method

@Propaganistas contributed a whereIn() route parameter constraint method, which can be used to match a route param against an array of allowed values:

Route::get('/foo/{bar}')->whereIn('bar', $values);

Batch Job Delay for Beanstalkd and SQS Queues

OMAR.A contributed to the ability to use batch jobs delay. Before these PR contributions, SQS and Beanstalkd ignored delay time when sending messages to the queue, and now, they consider the delay as expected.

use App\Jobs\ImportCsv;
use Illuminate\Bus\Batch;
use Illuminate\Support\Facades\Bus;
$batch = Bus::batch([
(new ImportCsv(1, 100))->delay($delay),
(new ImportCsv(101, 200))->delay($delay)

String Squish Helper

Dwight Watson contributed a squish() string helper to remove all "extra" blank space from a given string. Here are some examples from the pull request tests to get a visual of what squish does:

'laravel php framework',
Str::squish(' laravel php framework '));
'laravel php framework',
'laravel php framework',

Query Builder "whereJsonContainsKey()" Method

Derek MacDonald contributed a whereJsonContainsKey() method. It supports checking for array integer keys and supports SQLite. Here are some examples from the pull request description:


Dispatch Batch After a Response

OMAR.A contributed the ability to dispatch a batch after the response is sent to the user:

$batch = Bus::batch([
new ImportCsv(1, 100),
new ImportCsv(101, 200),
new ImportCsv(201, 300),
new ImportCsv(301, 400),
new ImportCsv(401, 500),
])->then(function (Batch $batch) {
// All jobs completed successfully...
})->catch(function (Batch $batch, Throwable $e) {
// First batch job failure detected...
})->finally(function (Batch $batch) {
// The batch has finished executing...
// also, it returns a batch object so you can access batch id
return $batch->id;

Release Notes

You can see the complete list of new features and updates below and the diff between 9.6.0 and 9.7.0 on GitHub. The following release notes are directly from the changelog:



  • Make whereBelongsTo accept Collection (#41733)
  • Database queries containing JSON paths support array index braces (#41767)
  • Fire event before route matched (#41765)
  • Added to Illuminate/Http/Resources/ConditionallyLoadsAttributes::whenNotNull method (#41769)
  • Added "whereIn" route parameter constraint method (#41794)
  • Added Illuminate/Queue/BeanstalkdQueue::bulk() (#41789)
  • Added Illuminate/Queue/SqsQueue::bulk() (#41788)
  • Added String::squish() helper (#41791)
  • Added query builder method whereJsonContainsKey() (#41802)
  • Enable dispatchAfterResponse for batch (#41787)


  • Factory generation fixes (#41688)
  • Fixed Http Client throw boolean parameter of retry method (#41762, #41792)
  • Ignore empty redis username string in PhpRedisConnector (#41773)
  • Fixed support of nullable type for AsArrayObject/AsCollection (#41797, 05846e7)
  • Fixed adding jobs from iterable to the pending batch (#41786)
  • Http client: fix retry handling of connection exception (#41811)


  • Enable batch jobs delay for database queue (#41758)
  • Enable batch jobs delay for redis queue (#41783)
  • Http client: dispatch "response received" event for every retry attempt (#41793)
  • Http Client: provide pending request to retry callback (#41779)
  • Allow non length limited strings and char for postgresql (#41800)
  • Revert some Carbon::setTestNow() removals (#41810)
  • Allow cleanup of databases when using parallel tests (#41806)

Filed in:

Paul Redmond

Full stack web developer. Author of Lumen Programming Guide and Docker for PHP Developers.