Outsource Laravel Development Partner - $3200/Month | Bacancy

Factory makeMany() Method in Laravel 12.52.0

Last updated on by

Factory makeMany() Method in Laravel 12.52.0 image

Laravel v12.52.0 adds a makeMany() factory method, new withoutAfterMaking() and withoutAfterCreating() factory helpers, atomic writes in the Blade compiler to prevent race conditions, and improved exception traces for closures and standalone functions.

Key highlights include:

  • New makeMany() factory method
  • withoutAfterMaking() and withoutAfterCreating() factory helpers
  • temporaryUploadUrl() support for local filesystem
  • Atomic writes in BladeCompiler to prevent race conditions
  • Mailable::later() delay fix and delay assertions for queued mailables
  • LazyCollection::random() $preserveKeys support
  • String-based expressions for selectExpression()
  • Closures and standalone functions display correctly in exception traces
  • Numerous bug fixes and internal improvements

What's New

makeMany() Factory Method

Factories now include a makeMany() method as a complement to createMany(). Where createMany() persists records to the database, makeMany() returns a collection of model instances without saving them — useful when you need multiple in-memory instances for unit tests or transformations:

// Create multiple unsaved instances
$users = User::factory()->makeMany(3);
 
// Equivalent longhand
$users = User::factory()->count(3)->make();

Pull Request: #58795

withoutAfterMaking() and withoutAfterCreating() Factory Helpers

Two new factory helpers let you skip afterMaking and afterCreating callbacks on a per-call basis. This is useful when a callback sets up relationships or fires side effects that are irrelevant to the current test:

// Skip afterMaking callbacks
$user = User::factory()->withoutAfterMaking()->make();
 
// Skip afterCreating callbacks
$user = User::factory()->withoutAfterCreating()->create();

Pull Request: #58794

temporaryUploadUrl() for Local Filesystem

The temporaryUploadUrl() method now works with the local filesystem driver, previously only available for cloud drivers like S3. This makes it possible to use temporaryUploadUrl() in local development and testing environments without needing to swap to a cloud driver:

$url = Storage::disk('local')->temporaryUploadUrl(
'uploads/photo.jpg',
now()->addMinutes(30)
);

Pull Request: #58499

Atomic Writes in BladeCompiler

The Blade compiler now uses atomic writes when caching compiled views and inline component views. Previously, a race condition could occur when multiple processes compiled the same view simultaneously, resulting in corrupted or partially-written cache files. The atomic write approach writes to a temporary file first, then moves it into place, eliminating the race:

Pull Requests: #58812, #58815

Mailable::later() Delay Fix and Delay Assertions

Mailable::later() was not correctly applying the delay to the dispatched SendQueuedMailable job. This is now fixed. A companion PR adds delay support to Mail::assertQueued() so you can assert that a mailable was queued with a specific delay:

Mail::fake();
 
Mail::to('user@example.com')->later(now()->addMinutes(10), new WelcomeMail());
 
Mail::assertQueued(WelcomeMail::class, function ($mail) {
return $mail->delay->equalTo(now()->addMinutes(10));
});

Pull Requests: #58765, #58787

LazyCollection::random() $preserveKeys Support

LazyCollection::random() now accepts a $preserveKeys parameter, matching the behavior already available on Collection::random(). When true, the original keys are preserved in the returned results:

$collection = LazyCollection::make(['a' => 1, 'b' => 2, 'c' => 3, 'd' => 4]);
 
// Preserves original keys
$sample = $collection->random(2, preserveKeys: true);
// e.g. ['b' => 2, 'd' => 4]

Pull Request: #58791

String-Based Expressions for selectExpression()

selectExpression() on the query builder now accepts raw strings in addition to Expression objects. This reduces boilerplate when you need a single raw expression in a select:

// Before
DB::table('orders')->selectExpression(DB::raw('SUM(total) as revenue'));
 
// After
DB::table('orders')->selectExpression('SUM(total) as revenue');

Pull Request: #58753

Closures Display Correctly in Exception Traces

Exception stack traces now correctly display closure and standalone function names instead of showing a generic or empty label. This makes debugging anonymous functions and Closure-based route handlers more readable in error pages and logs.

Pull Request: #58879

Bug Fixes and Improvements

Queue & Async:

  • Fix defer callbacks being discarded when using the sync queue (#58745)
  • Batch::progress() return value cast to int (#58767)

Database & Eloquent:

  • Fix empty Collection returned for non-model JSON:API resources (#58752)
  • Only merge cached casts for accessed attributes (#57627)
  • Revert SQL Server column precision checks that caused regressions (#58888)
  • MySQL connection string updated to use --ssl-mode=DISABLED for modern clients (#58786)

Testing:

  • Add option to opt out of parallel-safe cache prefix isolation (#58801)

Middleware:

  • Backport withMiddleware changes from 13.x (#58798)

Type Improvements & Documentation:

Upgrade Notes

No breaking changes are expected for typical applications. The SQL Server column precision revert restores behavior from before v12.51.0 — if you relied on the precision check behavior from that version, review your SQL Server migrations. Review the full changelog for complete details when upgrading.

References

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
Acquaint Softtech

Hire Laravel developers with AI expertise at $20/hr. Get started in 48 hours.

Visit Acquaint Softtech
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
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
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
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
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 Adds an Official Svelte + Inertia Starter Kit image

Laravel Adds an Official Svelte + Inertia Starter Kit

Read article
MongoDB Vector Search in Laravel: Finding the Unqueryable image

MongoDB Vector Search in Laravel: Finding the Unqueryable

Read article
Laravel Cloud Adds “Markdown for Agents” to Serve AI-Friendly Content image

Laravel Cloud Adds “Markdown for Agents” to Serve AI-Friendly Content

Read article
Laravel Releases Nightwatch MCP Server for Claude Code and AI Agents image

Laravel Releases Nightwatch MCP Server for Claude Code and AI Agents

Read article
Single Table Inheritance for Eloquent Models Using Parental image

Single Table Inheritance for Eloquent Models Using Parental

Read article
Laravel Live Denmark Returns to Copenhagen in August 2026 image

Laravel Live Denmark Returns to Copenhagen in August 2026

Read article