Code review at scale is broken. Here’s how Augment Code is fixing it.

Dynamic Cache, Database, and Mail Builders in Laravel 11.31

Last updated on by

Dynamic Cache, Database, and Mail Builders in Laravel 11.31 image

Never Miss a Laravel Release 🚀

Sign up and get an email with each new Laravel release

The Laravel team released v11.31, which includes dynamic cache/db/mail builders, a cache token repository, a URL::forceHttps() convenience method, and more.

Cache Token Repository

Andrew Brown contributed a cache token repository as an alternative way to store password reset tokens:

This PR proposes a new CacheTokenRepository which will allow the password reset tokens to be handled via cache. IMO cache is a perfect storage medium because it can be more ephemeral, just like the password reset tokens.

To enable this new CacheTokenRepository, adjust your config/auth.php like so:

'passwords' => [
 
//new cache driver
'customers' => [
'driver' => 'cache',
'store' => 'passwords',
'provider' => 'customers',
'expire' => 60,
'throttle' => 60,
],
 
//default old database driver
'users' => [
'provider' => 'users',
'table' =>'password_reset_tokens',
'expire' => 60,
'throttle' => 60,
],
],

See Pull Request #53428 for details on the implementation.

Dynamically Build Mailers On-Demand

Steve Bauman contributed the ability to dynamically build a mailer and send it using the Mail::build() method. This allows developers to create mailers based on a given configuration instead of being hard-coded in the config files:

use Illuminate\Support\Facades\Mail;
 
$mailer = Mail::build([
'transport' => 'smtp',
'host' => '127.0.0.1',
'port' => 587,
'encryption' => 'tls',
'username' => 'usr',
'password' => 'pwd',
'timeout' => 5,
]);
 
$mailer->send($mailable);

See Pull Request #53411 for discussion and implementation details.

Add DB::build() Method

Similar to the Mail::build() method, Steve Bauman contributed DB::build() to dynamically create new DB connections that are not defined in your configuration file:

use Illuminate\Support\Facades\DB;
 
$sqlite = DB::build([
'driver' => 'sqlite',
'database' => ':memory:',
]);
 
$mysql = DB::build([
'driver' => 'mysql',
'database' => 'forge',
'username' => 'root',
'password' => 'secret',
]);
 
$pgsql = DB::build([
'driver' => 'pgsql',
// ...
]);
 
$sqlsrv = DB::build([
'driver' => 'sqlsrv',
// ...
]);

See Pull Request #53464 for details.

Add Cache::build() to Create On-demand Cache Repositories

Steve Bauman contributed the ability to dynamically build Cache repositories on-demand using the Cache::build() method. Similar to the DB and Mailer dynamic build method, you can create cache repositories not defined in your configuration file:

use Illuminate\Support\Facades\Cache;
 
$apc = Cache::build([
'driver' => 'apc',
]);
 
$array = Cache::build([
'driver' => 'array',
'serialize' => false,
]);
 
$database = Cache::build([
'driver' => 'database',
'table' => 'cache',
'connection' => null,
'lock_connection' => null,
]);
 
$file = Cache::build([
'driver' => 'file',
'path' => storage_path('framework/cache/data'),
]);

See Pull Request #53454 for implementation details.

Batch and Chain onQueue() Method Accepts Backed Enums

Philip Iezzi contributed the ability to use a backed enumeration with the onQueue() method of a Bus chain:

// Before
Bus::chain($jobs)
->onQueue(QueueName::long->value)->dispatch();
 
// After
Bus::chain($jobs)
->onQueue(QueueName::long)->dispatch();

See Pull Request #53359 for implementation details.

Add Application removeDeferredServices() Method

Ollie Read contributed the removeDeferredServices() application method to remove a deferred service from the application container.

// Before
$deferredServices = $app->getDeferredServices();
 
unset($deferredServices['auth.password'], $deferredServices['auth.password.broker']);
 
$app->setDeferredServices($deferredServices);
 
// After
$app->removeDeferredServices(['auth.password', 'auth.password.broker']);

This use-case isn't a common one that you'll need, but this method compliments to get and set methods of deferred services nicely. See Pull Request #53362 for details.

Ability to Append and Prepend Middleware Priority from the Application Builder

Ollie Read contributed another low-level change to append and prepend middleware priority to the application builder, allowing access to add middleware after/before methods on the kernel:

return Application::configure(basePath: dirname(__DIR__))
->withRouting(
web: __DIR__.'/../routes/web.php',
commands: __DIR__.'/../routes/console.php',
health: '/up',
)
->withMiddleware(function (Middleware $middleware) {
$middleware->appendToPriorityList(
[
\Illuminate\Cookie\Middleware\EncryptCookies::class,
\Illuminate\Contracts\Auth\Middleware\AuthenticatesRequests::class,
],
\Illuminate\Routing\Middleware\ValidateSignature::class
);
 
$middleware->prependToPriorityList(
[
\Illuminate\Cookie\Middleware\EncryptCookies::class,
\Illuminate\Contracts\Auth\Middleware\AuthenticatesRequests::class,
],
\Illuminate\Routing\Middleware\ValidateSignature::class
);
})
->withExceptions(function (Exceptions $exceptions) {
//
})->create();

See Pull Request #53326 for further details.

Add forceHttps() Method to Enforce HTTPs Scheme for URLs

Dasun Tharanga contributed the forceHttps() method, which simplifies enforcing HTTPs for URLs requiring such. The method accepts a boolean, making it easy to force HTTPs for a given set of environments:

URL::forceHttps(
$this->app->isProduction()
);
 
URL::forceHttps(
$this->app->environment('staging', 'production')
);

See Pull Request #53381 for implementation details.

Release notes

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

v11.31.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
Laravel Cloud

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

Visit Laravel Cloud
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
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
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
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
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
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 →
Laravel Gets a Claude Code Simplifier Plugin image

Laravel Gets a Claude Code Simplifier Plugin

Read article
Laravel Boost Update Adds Support for the New MCP Protocol image

Laravel Boost Update Adds Support for the New MCP Protocol

Read article
Pest Adds withHost for Browser Testing Subdomains in Laravel image

Pest Adds withHost for Browser Testing Subdomains in Laravel

Read article
Run Artisan Make Commands in Laravel VS Code Extension image

Run Artisan Make Commands in Laravel VS Code Extension

Read article
Livewire 4 Is Dropping Next Week, and wire:transition Makes Animations Effortless image

Livewire 4 Is Dropping Next Week, and wire:transition Makes Animations Effortless

Read article
Laravel 12.45.1, 12.45.2, and 12.46.0 Released image

Laravel 12.45.1, 12.45.2, and 12.46.0 Released

Read article