Laravel 9.51 Released

Published on by

Laravel 9.51 Released image

Never Miss a Laravel Release 🚀

Sign up and get an email with each new Laravel release

The Laravel team released 9.51 this week with a new database query count expectation, relationship builder for one/many through, HTTP URI templates, and more.

Before we get to the main Laravel framework release, this week also saw some cool new features throughout the Laravel ecosystem. The fact that all this is shipping a week before Laravel 10 still blows my mind!

Laravel Sail add command

Tony Messias contributed a sail:add command that you can use to add new services to an existing Sail installation.

Laravel Dusk database truncation

Patrick O'Meara contributed a DatabaseTruncation trait that will migrate your database and then truncate your tables to speed up rerunning database migrations. See the Dusk Using Database Truncations documentation for further details.

Now, onto what's new in Laravel 9.51:

Database query count test expectation

Tim MacDonald contributed a test expectation for database query count. This expectation can ensure code doesn't inadvertently introduce new database queries:

public function testItWorksEfficiently()
{
$this->expectsDatabaseQueryCount(5);
 
// do stuff...
 
// throws an exception on tearDown if more than 5 queries have run
// since the expectation was created.
}

Pending "has many through" and "has one through" builder

Tim MacDonald contributed a pending builder for has-one-through and has-many-through relationships. The example given in Pull Request #45894 has the following relationships:

  • Project -> Has Many -> Environment
  • Environment -> Has Many -> Deployment

Given the above relationships, here's how you can write a "has many through" relationship with the pending builder:

class Project extends Model
{
public function deployments()
{
return $this->through($this->environments())
->has(fn (Environment $env) => $env->deployments());
}
 
public function environments()
{
return $this->hasMany(Environment::class);
}
}

To illustrate the "has one through" relationship, take the following existing relationships:

  • Mechanic -> Has One -> Car
  • Car -> Has One -> Owner

Given the above relationships, here's how you can write the "has one through" relationship with the pending builder:

class Mechanic extends Model
{
public function owner()
{
return $this->through($this->car())
->has(fn (Car $car) => $car->owner());
}
 
public function car()
{
return $this->hasOne(Car::class);
}
}

See the Has Many Through and the Has One Through documentation for further details on relationships with Laravel.

HTTP client URI templates

James Brooks contributed URI templates to the Laravel HTTP client, which uses guzzlehttp/uri-templates under the hood:

Http::withUrlParameters([
'endpoint' => 'https://laravel.com',
'page' => 'docs',
'version' => '9.x',
'thing' => 'validation',
])->get('{+endpoint}/{page}/{version}/{thing}');
 
// https://laravel.com/docs/9.x/validation

Release Notes

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

v9.51.0

Added

  • Added Illuminate/Foundation/Testing/Concerns/InteractsWithDatabase::expectsDatabaseQueryCount() (#45932)
  • Added pending has-many-through and has-one-through builder (#45894)
  • Added Illuminate/Http/Client/PendingRequest::withUrlParameters() (#45982)

Fixed

  • Fix: prevent duplicated content-type on HTTP client (#45960)
  • Add missing php extensions in composer (#45941)

Changed

  • Command schedule:work minor features: schedule:run output file & environment specific verbosity (#45949)
  • Added missing self reserved word to reservedNames array in Illuminate/Console/GeneratorCommand.php (#46001)
  • pass value along to ttl callback in Illuminate/Cache/Repository::remember() (#46006)
  • Make sure the lock_connection is used for schedule's withoutOverlapping() (#45963)
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
SerpApi

The Web Search API for Your LLM and AI Applications

Visit SerpApi
Tinkerwell logo

Tinkerwell

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

Tinkerwell
Kirschbaum logo

Kirschbaum

Providing innovation and stability to ensure your web application succeeds.

Kirschbaum
PhpStorm logo

PhpStorm

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

PhpStorm
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
No Compromises logo

No Compromises

Joel and Aaron, the two seasoned devs from the No Compromises podcast, are now available to hire for your Laravel project. ⬧ Flat rate of $9500/mo. ⬧ No lengthy sales process. ⬧ No contracts. ⬧ 100% money back guarantee.

No Compromises
Laravel Cloud logo

Laravel Cloud

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

Laravel Cloud
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
Acquaint Softtech logo

Acquaint Softtech

Acquaint Softtech offers AI-ready Laravel developers who onboard in 48 hours at $3000/Month with no lengthy sales process and a 100 percent money-back guarantee.

Acquaint Softtech
Shift logo

Shift

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

Shift

The latest

View all →
Showcase Your PhpStorm Expertise on LinkedIn image

Showcase Your PhpStorm Expertise on LinkedIn

Read article
Privacy Filter: Detect PII in Text from Laravel image

Privacy Filter: Detect PII in Text from Laravel

Read article
NationForge: A Self-Hosted Admin Panel for Civic Organizations image

NationForge: A Self-Hosted Admin Panel for Civic Organizations

Read article
Monitor Laravel Queues, Commands, and Schedulers on Any Driver with Vigilance image

Monitor Laravel Queues, Commands, and Schedulers on Any Driver with Vigilance

Read article
Watch the Teaser for 'The Story of PHP' Documentary image

Watch the Teaser for 'The Story of PHP' Documentary

Read article
Ship AI with Laravel: Give Your AI Agent Live Web Search image

Ship AI with Laravel: Give Your AI Agent Live Web Search

Read article