Friday, May 17, 2024
HomePHPLaravel 9.31 Launched | Laravel Information

Laravel 9.31 Launched | Laravel Information


The Laravel staff launched 9.31 with a request lifecycle length handler, replace mannequin with out altering timestamps, pretend batches for testing, and extra:

Request lifecycle length handler

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

1use CarbonCarbonInterval as Interval;

2use IlluminateContractsHttpKernel;

3 

4public perform boot()

5{

6 if ($this->app->runningInConsole()) {

7 return;

8 }

9 

10 $kernel = $this->app[Kernel::class];

11 $kernel->whenRequestLifecycleIsLongerThan(

12 Interval::seconds(1),

13 fn ($startedAt, $request, $response) => /* ... */

14 );

15}

This callback is just like the cumulative database question time launched in Laravel 9.18 Launched, however for the request lifecycle.

Mannequin “with out timestamps” function

Tim MacDonald contributed a static withoutTimestamps() technique the place updated_at is not going to change:

1$consumer = Consumer::first();

2 

3 

4// `updated_at` will not be modified...

5 

6Consumer::withoutTimestamps(

7 fn () => $consumer->replace(['reserved_at' => now()])

8);

Vite manifestHash perform

Enzo Innocenzi contributed a manifestHash() technique to the Vite class, that returns a singular hash if the manifest exists. This can be utilized to invalidate property. See Pull Request #44136 for additional particulars.

Pretend batches

Taylor Otwell contributed pretend batches:

It is at present laborious to check issues like if a batch was cancelled by a job or if a job added extra jobs to a batch. You must create a FakeBatch manually and override the cancel / add strategies, and so forth.

This solves that.

1[$job, $batch] = (new TestJob)->withFakeBatch();

2 

3$job->deal with();

4 

5$this->assertTrue($batch->cancelled());

6$this->assertNotEmpty($batch->added);

Mannequin getAppends() technique

Arturo Rodríguez added an accessor technique to Mannequin to get the accessors which might be being appended to mannequin arrays. This may very well be helpful for customized mannequin mappings:

1$mannequin->getAppends();

Str wrap static technique

Steve Bauman added a lacking static Str::wrap() technique, which was solely obtainable through Stringable:

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

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

Macroable vite

Tim MacDonald contributed the Macroable trait to IlluminateFoundationVite to create aliases matching your JS config:

1Vite::macro('picture', fn ($asset) => $this->asset("assets/photos/{$asset}"));

2 

3// Utilization: <img src="{{ Vite::picture('profile.png') }}" ... >

See Pull Request #44198 for additional particulars.

Launch Notes

You’ll be able to see the whole listing of latest options and updates under and the diff between 9.30.0 and 9.31.0 on GitHub. The next launch notes are straight from the changelog:

v9.31.0

Added

  • Added distinctive deferrable initially deferred constants for PostgreSQL (#44127)
  • Request lifecycle length handler (#44122)
  • Added Mannequin::withoutTimestamps(…) (#44138)
  • Added manifestHash perform to IlluminateFoundationVite (#44136)
  • Added help for operator <=> in /Illuminate/Collections/Traits/EnumeratesValues::operatorForWhere() (#44154)
  • Added that Illuminate/Database/Connection::registerDoctrineType() can settle for object in addition to classname for brand new doctrine kind (#44149)
  • Added Pretend Batches (#44104, #44173)
  • Added Mannequin::getAppends() (#44180)
  • Added lacking Str::wrap() static technique (#44207)
  • Added require symfony/uid (#44202)
  • Make Vite macroable (#44198)

Fastened

  • Async repair in Illuminate/Http/Shopper/PendingRequest (#44179)
  • Fixes artisan serve command with PHP_CLI_SERVER_WORKERS atmosphere variable (#44204)
  • Fastened InteractsWithDatabase::castAsJson($worth) incorrectly handles SQLite Database (#44196)

Modified

  • Enhance Blade compilation exception messages (#44134)
  • Enhance take a look at failure output (#43943)
  • Immediate to create MySQL db when migrating (#44153)
  • Enhance UUID and ULID help for Eloquent (#44146)
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments