Laravel 9.31 Released

Published on by

Laravel 9.31 Released image

The Laravel team released 9.31 with a request lifecycle duration handler, update model without changing timestamps, fake batches for testing, and more:

Request lifecycle duration handler

Tim MacDonald contributed a callback handler when a request lifecycle is longer than a given time limit:

use Carbon\CarbonInterval as Interval;
use Illuminate\Contracts\Http\Kernel;
 
public function boot()
{
if ($this->app->runningInConsole()) {
return;
}
 
$kernel = $this->app[Kernel::class];
$kernel->whenRequestLifecycleIsLongerThan(
Interval::seconds(1),
fn ($startedAt, $request, $response) => /* ... */
);
}

This callback is similar to the cumulative database query time released in Laravel 9.18 Released, but for the request lifecycle.

Model "without timestamps" feature

Tim MacDonald contributed a static withoutTimestamps() method where updated_at will not change:

$user = User::first();
 
 
// `updated_at` is not changed...
 
User::withoutTimestamps(
fn () => $user->update(['reserved_at' => now()])
);

Vite manifestHash function

Enzo Innocenzi contributed a manifestHash() method to the Vite class, that returns a unique hash if the manifest exists. This can be used to invalidate assets. See Pull Request #44136 for further details.

Fake batches

Taylor Otwell contributed fake batches:

It's currently hard to test things like if a batch was cancelled by a job or if a job added additional jobs to a batch. You have to create a FakeBatch manually and override the cancel / add methods, etc.

This solves that.

[$job, $batch] = (new TestJob)->withFakeBatch();
 
$job->handle();
 
$this->assertTrue($batch->cancelled());
$this->assertNotEmpty($batch->added);

Model getAppends() method

Arturo Rodríguez added an accessor method to Model to get the accessors that are being appended to model arrays. This could be useful for custom model mappings:

$model->getAppends();

Str wrap static method

Steve Bauman added a missing static Str::wrap() method, which was only available via Stringable:

Str::wrap('-bar-', 'foo', 'baz'); // 'foo-bar-baz'
str('-bar-')->wrap('foo', 'baz'); // 'foo-bar-baz'

Macroable vite

Tim MacDonald contributed the Macroable trait to Illuminate\Foundation\Vite to create aliases matching your JS config:

Vite::macro('image', fn ($asset) => $this->asset("resources/images/{$asset}"));
 
// Usage: <img src="{{ Vite::image('profile.png') }}" ... >

See Pull Request #44198 for further details.

Release Notes

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

v9.31.0

Added

  • Added unique deferrable initially deferred constants for PostgreSQL (#44127)
  • Request lifecycle duration handler (#44122)
  • Added Model::withoutTimestamps(...) (#44138)
  • Added manifestHash function to Illuminate\Foundation\Vite (#44136)
  • Added support for operator <=> in /Illuminate/Collections/Traits/EnumeratesValues::operatorForWhere() (#44154)
  • Added that Illuminate/Database/Connection::registerDoctrineType() can accept object as well as classname for new doctrine type (#44149)
  • Added Fake Batches (#44104, #44173)
  • Added Model::getAppends() (#44180)
  • Added missing Str::wrap() static method (#44207)
  • Added require symfony/uid (#44202)
  • Make Vite macroable (#44198)

Fixed

  • Async fix in Illuminate/Http/Client/PendingRequest (#44179)
  • Fixes artisan serve command with PHP_CLI_SERVER_WORKERS environment variable (#44204)
  • Fixed InteractsWithDatabase::castAsJson($value) incorrectly handles SQLite Database (#44196)

Changed

  • Improve Blade compilation exception messages (#44134)
  • Improve test failure output (#43943)
  • Prompt to create MySQL db when migrating (#44153)
  • Improve UUID and ULID support for Eloquent (#44146)
Paul Redmond photo

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

Filed in:
Cube

Laravel Newsletter

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

image
Laravel Forge

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

Visit Laravel Forge
Laravel Forge logo

Laravel Forge

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

Laravel Forge
Tinkerwell logo

Tinkerwell

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

Tinkerwell
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 $7500/mo. ⬧ No lengthy sales process. ⬧ No contracts. ⬧ 100% money back guarantee.

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

Bacancy

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

Bacancy
Lucky Media logo

Lucky Media

Bespoke software solutions built for your business. We ♥ Laravel

Lucky Media
Lunar: Laravel E-Commerce logo

Lunar: Laravel E-Commerce

E-Commerce for Laravel. An open-source package that brings the power of modern headless e-commerce functionality to Laravel.

Lunar: Laravel E-Commerce
LaraJobs logo

LaraJobs

The official Laravel job board

LaraJobs
All Green logo

All Green

All Green is a SaaS test runner that can execute your whole Laravel test suite in mere seconds so that you don't get blocked – you get feedback almost instantly and you can deploy to production very quickly.

All Green
Larafast: Laravel SaaS Starter Kit logo

Larafast: Laravel SaaS Starter Kit

Larafast is a Laravel SaaS Starter Kit with ready-to-go features for Payments, Auth, Admin, Blog, SEO, and beautiful themes. Available with VILT and TALL stacks.

Larafast: Laravel SaaS Starter Kit
SaaSykit: Laravel SaaS Starter Kit logo

SaaSykit: Laravel SaaS Starter Kit

SaaSykit is a 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
Rector logo

Rector

Your partner for seamless Laravel upgrades, cutting costs, and accelerating innovation for successful companies

Rector

The latest

View all →
Property Hooks Get Closer to Becoming a Reality in PHP 8.4 image

Property Hooks Get Closer to Becoming a Reality in PHP 8.4

Read article
Asserting Exceptions in Laravel Tests image

Asserting Exceptions in Laravel Tests

Read article
Reversible Form Prompts and a New Exceptions Facade in Laravel 11.4 image

Reversible Form Prompts and a New Exceptions Facade in Laravel 11.4

Read article
Basset is an alternative way to load CSS & JS assets image

Basset is an alternative way to load CSS & JS assets

Read article
Integrate Laravel with Stripe Connect Using This Package image

Integrate Laravel with Stripe Connect Using This Package

Read article
The Random package generates cryptographically secure random values image

The Random package generates cryptographically secure random values

Read article