Ehsan Bagherzadegan
Back to articles
5 min read

Laravel 13.42: Typed UUID/ULID Input, MigrationFailed Event, and Scheduler Improvements

Laravel 13.42 adds typed uuid() and ulid() request helpers, a MigrationFailed event for safer MySQL deployments, scheduler skip reasons, Uri::origin() for clean origin comparison, and customizable lost-connection detection.

Laravel 13.42 arrived on November 10 with a handful of focused improvements that solve real problems developers hit in production. The headliners are typed UUID and ULID input helpers and a MigrationFailed event for safer deployments, but the release also adds scheduler skip reasons, a cleaner way to compare URL origins, custom lost-connection detection, and macroable processes.

Typed UUID and ULID Input Helpers

Laravel has had uuid validation rules for years, but extracting a validated UUID from a request meant writing the same boilerplate: validate, then instantiate a Ramsey\Uuid\Uuid object. The new uuid() and ulid() methods on the InteractsWithData trait (available on requests, validated data, Fluent objects, URI query strings, component attributes, and command input) return typed objects directly.

// Returns Ramsey\Uuid\UuidInterface|null
$orderId = $request->uuid('order_id');

// Returns Symfony\Component\Uid\Ulid|null
$eventId = $request->ulid('event_id');

Missing or empty input returns null. Invalid input throws an exception — no silent coercion to a zero UUID. This matches the strict casting behavior added to integer(), float(), boolean(), and string() in 13.40.

The methods work anywhere InteractsWithData is used:

// Validated data
$data = $request->validate([
    'user_id' => 'required|uuid',
]);
$userId = $data->uuid('user_id'); // Ramsey\Uuid\UuidInterface

// Artisan command input
$userId = $this->input()->uuid('user_id');

// Component attributes
$userId = $attributes->uuid('user_id');

Under the hood, uuid() uses Ramsey's Uuid::fromString() and ulid() uses Symfony's Ulid::fromString(), so you get the full API of those objects — ->toString(), ->getBytes(), ->getHex(), comparison methods, and so on — without an extra line of code.

MigrationFailed Event

Deployments that run migrations on MySQL have always carried a quiet risk: ALTER TABLE statements aren't transactional. If a migration fails halfway through, the schema is left in a half-applied state, but the application may still boot and serve requests against broken tables.

Laravel 13.42 introduces Illuminate\Database\Events\MigrationFailed. It fires when any migration throws, before the exception propagates. The event carries:

  • migration — the migration class name
  • method — up or down
  • name — the migration file name
  • exception — the thrown \Throwable
use Illuminate\Database\Events\MigrationFailed;
use Illuminate\Support\Facades\Event;

Event::listen(MigrationFailed::class, function (MigrationFailed $event) {
    // Alert on-call, disable the app, log to Datadog, etc.
    Log::critical('Migration failed', [
        'migration' => $event->migration,
        'method' => $event->method,
        'exception' => $event->exception->getMessage(),
    ]);
});

The exception is still thrown after the event fires, so the migration command exits with a non-zero code and your deployment pipeline fails as expected. The event is purely for observability and automated response — pausing traffic, notifying the team, or triggering a rollback script — before users hit the broken schema.

This pairs well with the MigrationStarted and MigrationEnded events that already existed, giving you a complete lifecycle hook set for deployment tooling.

Scheduler: Skip Reasons and Per-Task Timezones

The ScheduledTaskSkipped event (added in 13.40) now includes a reason property typed as the new ScheduledTaskSkipReason enum:

enum ScheduledTaskSkipReason: string
{
    case ConditionNotMet = 'condition_not_met';
    case Paused = 'paused';
    case RanOnAnotherServer = 'ran_on_another_server';
}

This lets you distinguish between "the ->when() closure returned false" and "the task ran on another server because of ->onOneServer()" in your monitoring or logging.

The schedule:list --json output also now includes each task's own cron expression and timezone, making it easier to audit schedules across a multi-timezone application.

Uri::origin() for Clean Origin Comparison

Comparing URLs for same-origin checks used to mean normalizing scheme, host, and port yourself. Uri::origin() does it for you:

use Illuminate\Support\Uri;

$uri = Uri::parse('https://App.Example.COM:443/path?query=1');
$uri->origin(); // "https://app.example.com"

The returned string is lowercased, has the default port stripped (443 for HTTPS, 80 for HTTP), and contains only scheme, host, and port — exactly what you need for CORS checks, referrer validation, or any same-origin logic.

LostConnectionDetector::detectUsing()

The database connection loss detector (used by the queue worker and long-running commands to reconnect automatically) can now be customized without binding a full replacement class:

use Illuminate\Database\DetectsLostConnections\LostConnectionDetector;

LostConnectionDetector::detectUsing(function (\Throwable $e, \PDO $pdo): bool {
    // Your custom logic: check error codes, SQLSTATE, vendor-specific messages
    return $e->getCode() === '08006' || str_contains($e->getMessage(), 'server closed the connection');
});

The callback receives the exception and the PDO instance. Return true to treat it as a lost connection and trigger a reconnect. This is useful for non-standard database proxies, cloud SQL instances with custom error codes, or any edge case where the built-in detector misses a disconnect.

PendingProcess Is Now Macroable

PendingProcess (the fluent builder for Process::run() and Process::start()) accepts macros anywhere in the chain:

use Illuminate\Support\Process;

Process::macro('withTimeout', function (int $seconds) {
    return $this->timeout($seconds)->idleTimeout($seconds);
});

Process::run('long-running-command')->withTimeout(300);

This is a small but nice quality-of-life improvement for teams that wrap common process patterns (timeouts, signal handling, environment setup) into reusable macros.

When to Reach for These

Feature Use when
uuid() / ulid() You accept UUID/ULID input in requests, commands, or components and want typed objects without manual parsing.
MigrationFailed event You run migrations on MySQL/MariaDB in production and want automated alerts or traffic pausing on failure.
ScheduledTaskSkipReason You monitor scheduler health and need to distinguish "intentionally skipped" from "ran elsewhere."
Uri::origin() You compare origins for CORS, referrer checks, or security policies.
LostConnectionDetector::detectUsing() The built-in detector doesn't catch your database's disconnect errors.
PendingProcess macros You repeat the same process configuration across commands or jobs.

Takeaway

Laravel 13.42 doesn't introduce a flagship feature — it ships a set of targeted fixes that remove boilerplate (typed UUID/ULID input), close a deployment blind spot (MigrationFailed), and make existing tools more observable (scheduler skip reasons, per-task timezones). If you're on 13.x, it's a safe, low-risk upgrade with immediate practical value.

Sources