Laravel Cloud is here! Zero-config managed infrastructure for Laravel apps. Deploy now.

Laravel 10.19 Released

Published on by

Laravel 10.19 Released image

This week, the Laravel team released v10.19 with a collection percentage method, custom event discovery class resolution, dynamic queue listener delay, and more:

Word wrap string method

Josh Bonnick contributed a wordWrap method to the Laravel String API, which splits strings within a string using a character limit. This method is a wrapper for PHP's wordwrap function:

use Illuminate\Support\Str;
 
$text = "A very long woooooooooooord."
 
// Str
Str::wordWrap(string: $text, characters: 8);
/*
A very
long
wooooooo
ooooord.
*/
 
// Stringable
str($text)->wordWrap(string: $text, characters: 8);

Add percentage method to collections

Wendell Adriel contributed a percentage() method to collections that allows you to calculate a percentage based on custom logic using a truth test:

$collection = new $collection([
['name' => 'Taylor', 'foo' => 'foo'],
['name' => 'Nuno', 'foo' => 'bar'],
['name' => 'Dries', 'foo' => 'bar'],
['name' => 'Jess', 'foo' => 'baz'],
]);
 
$collection->percentage(fn ($value) => $value['foo'] === 'foo'); // 25.00
$collection->percentage(fn ($value) => $value['foo'] === 'bar'); // 50.00
$collection->percentage(fn ($value) => $value['foo'] === 'baz'); // 25.00
$collection->percentage(fn ($value) => $value['foo'] === 'test'); // 0.00

Ability to customize class resolution in Event discovery

@bastien-phi contributed the ability to customize class resolution for Event discovery:

This PR adds the ability to customize the way the translation is done and unlocks event discovery in such DDD structures.

Here's an example of a custom callback in Pull Request #48031's tests, which illustrates how this can be used:

use Illuminate\Foundation\Events\DiscoverEvents;
 
DiscoverEvents::guessClassNamesUsing(function (SplFileInfo $file, $basePath) {
return Str::of($file->getRealPath())
->after($basePath.DIRECTORY_SEPARATOR)
->before('.php')
->replace(DIRECTORY_SEPARATOR, '\\')
->ucfirst()
->prepend('Illuminate\\')
->toString();
});

Specify listener delay dynamically

@CalebW contributed support for listeners to define a withDelay() method that can determine queue listener delay:

class Listener implements ShouldQueue
{
public function __invoke(Event $event): void
{
// ...
}
 
public function withDelay(Event $event): int
{
return $event->fooBar
? <short_delay>
: <long_delay>;
}
}

Add dynamic return types to the rescue helper

Choraimy Kroonstuiver contributed a PHPDoc update to help static analysis tools understand the generic return types of the rescue() helper. There are no code examples to see here, but the updated Docblock looks as follows after this update:

/**
* Catch a potential exception and return a default value.
*
* @template TRescueValue
* @template TRescueFallback
*
* @param callable(): TRescueValue $callback
* @param (callable(\Throwable): TRescueFallback)|TRescueFallback $rescue
* @param bool|callable $report
* @return TRescueValue|TRescueFallback
*/
function rescue(callable $callback, $rescue = null, $report = true)
{
// ...
}
 
// Examples:
 
assertType('int|null', rescue(fn () => 123));
assertType('int', rescue(fn () => 123, 345));
assertType('int', rescue(fn () => 123, fn () => 345));

You can learn more about Generics By Examples on the PHPStan blog.

Add count argument to createMany and createManyQuietly

Jordan Welch contributed the ability to pass an integer to createMany() and createManyQuietly() on model factories to create that number of models:

// Before:
$users = User::factory()->createMany([[], [], []]);
 
// After:
$users = User::factory()->createMany(3);
 
$this->assertCount(3, $users);
$this->assertInstanceOf(Eloquent\Collection::class, $users);

Release notes

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

v10.19.0

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
Bacancy

Outsource a dedicated Laravel developer for $2,500/month. With over a decade of experience in Laravel development, we deliver fast, high-quality, and cost-effective solutions at affordable rates.

Visit Bacancy
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 $2500/month. Get 160 hours of dedicated expertise & a risk-free 15-day trial. Schedule a call now!

Bacancy
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
Cut PHP Code Review Time & Bugs into Half with CodeRabbit logo

Cut PHP Code Review Time & Bugs into Half with CodeRabbit

CodeRabbit is an AI-powered code review tool that specializes in PHP and Laravel, running PHPStan and offering automated PR analysis, security checks, and custom review features while remaining free for open-source projects.

Cut PHP Code Review Time & Bugs into Half with CodeRabbit
Join the Mastering Laravel community logo

Join the Mastering Laravel community

Connect with experienced developers in a friendly, noise-free environment. Get insights, share ideas, and find support for your coding challenges. Join us today and elevate your Laravel skills!

Join the Mastering Laravel community
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
Lucky Media logo

Lucky Media

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

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
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 →
Auto-translate Application Strings with Laratext image

Auto-translate Application Strings with Laratext

Read article
Simplify Factory Associations with Laravel's UseFactory Attribute image

Simplify Factory Associations with Laravel's UseFactory Attribute

Read article
Improved Installation and Frontend Hooks in Laravel Echo 2.1 image

Improved Installation and Frontend Hooks in Laravel Echo 2.1

Read article
Filter Model Attributes with Laravel's New except() Method image

Filter Model Attributes with Laravel's New except() Method

Read article
Arr::from() Method in Laravel 12.14 image

Arr::from() Method in Laravel 12.14

Read article
Streamline API Resources with Laravel's Fluent Methods image

Streamline API Resources with Laravel's Fluent Methods

Read article