The go-to PHP IDE with extensive out-of-the-box support for Laravel and its ecosystem.

Laravel 9.7 Released

Published on by

Laravel 9.7 Released image

Never Miss a Laravel Release 🚀

Sign up and get an email with each new Laravel release

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
$query
->whereBelongsTo($category[0])
->orWhereBelongsTo($category[1])
// ...
 
// Or...
$query->whereIn('category_id', $categories->modelKeys());
 
 
// >=9.7 can use collections:
$query->whereBelongsTo($categories);
$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:

DB::table('json_table')
->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)
])->dispatch();

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:

$this->assertSame(
'laravel php framework',
Str::squish(' laravel php framework '));
 
$this->assertSame(
'laravel php framework',
Str::squish("laravel\t\tphp\n\nframework")
);
 
$this->assertSame(
'laravel php framework',
Str::squish('
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:

DB::table('users')
->whereJsonContainsKey('options->languages')
->get();
 
DB::table('users')
->whereJsonDoesntContainKey('options->language->primary')
->get();
 
DB::table('users')
->whereJsonContainsKey('options->2fa[0]')
->get();
 
DB::table('users')
->whereJsonDoesntContainKey('options->2fa[0][1]')
->get();

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...
})->dispatchAfterResponse();
 
// 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:

v9.7.0

Added

  • 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)

Fixed

  • 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)

Changed

  • 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)
Paul Redmond photo

Staff writer at Laravel News. Full stack web developer and author.

Cube

Laravel Newsletter

Join 40k+ other developers and never miss out on new tips, tutorials, and more.

image
Tinkerwell

Enjoy coding and debugging in an editor designed for fast feedback and quick iterations. It's like a shell for your application – but with multi-line editing, code completion, and more.

Visit Tinkerwell
Curotec logo

Curotec

World class Laravel experts with GenAI dev skills. LATAM-based, embedded engineers that ship fast, communicate clearly, and elevate your product. No bloat, no BS.

Curotec
Bacancy logo

Bacancy

Supercharge your project with a seasoned Laravel developer with 4-6 years of experience for just $3200/month. Get 160 hours of dedicated expertise & a risk-free 15-day trial. Schedule a call now!

Bacancy
Tinkerwell logo

Tinkerwell

The must-have code runner for Laravel developers. Tinker with AI, autocompletion and instant feedback on local and production environments.

Tinkerwell
Get expert guidance in a few days with a Laravel code review logo

Get expert guidance in a few days with a Laravel code review

Expert code review! Get clear, practical feedback from two Laravel devs with 10+ years of experience helping teams build better apps.

Get expert guidance in a few days with a Laravel code review
PhpStorm logo

PhpStorm

The go-to PHP IDE with extensive out-of-the-box support for Laravel and its ecosystem.

PhpStorm
Laravel Cloud logo

Laravel Cloud

Easily create and manage your servers and deploy your Laravel applications in seconds.

Laravel Cloud
Kirschbaum logo

Kirschbaum

Providing innovation and stability to ensure your web application succeeds.

Kirschbaum
Shift logo

Shift

Running an old Laravel version? Instant, automated Laravel upgrades and code modernization to keep your applications fresh.

Shift
Harpoon: Next generation time tracking and invoicing logo

Harpoon: Next generation time tracking and invoicing

The next generation time-tracking and billing software that helps your agency plan and forecast a profitable future.

Harpoon: Next generation time tracking and invoicing
Lucky Media logo

Lucky Media

Get Lucky Now - the ideal choice for Laravel Development, with over a decade of experience!

Lucky Media
SaaSykit: Laravel SaaS Starter Kit logo

SaaSykit: Laravel SaaS Starter Kit

SaaSykit is a Multi-tenant Laravel SaaS Starter Kit that comes with all features required to run a modern SaaS. Payments, Beautiful Checkout, Admin Panel, User dashboard, Auth, Ready Components, Stats, Blog, Docs and more.

SaaSykit: Laravel SaaS Starter Kit

The latest

View all →
Livewire 4 Support in Laravel VS Code Extension v1.4.3 image

Livewire 4 Support in Laravel VS Code Extension v1.4.3

Read article
Fair Queue Distribution with Laravel Balanced Queue image

Fair Queue Distribution with Laravel Balanced Queue

Read article
Migrating Laravel News from Laravel Forge to Cloud image

Migrating Laravel News from Laravel Forge to Cloud

Read article
Laravel News Is the Live Stream Partner for Laracon EU 2026 image

Laravel News Is the Live Stream Partner for Laracon EU 2026

Read article
Query Builder Expression Aliases in Laravel 12.48 image

Query Builder Expression Aliases in Laravel 12.48

Read article
Restrict User Actions with Time-Based Sanctions Using Laravel Prohibitions image

Restrict User Actions with Time-Based Sanctions Using Laravel Prohibitions

Read article