Laravel New in 12: First-Class Typed Config, Slim Skeletons, and Upgrade Notes
#laravel #laravel-12 #php #upgrade

Laravel New in 12: First-Class Typed Config, Slim Skeletons, and Upgrade Notes

3 min read Mohamed Said Mohamed Said

What Actually Changed in Laravel 12

Laravel 12 is a focused release rather than a sweeping rewrite. The headline additions are typed configuration objects, a significantly slimmer default application skeleton, and a handful of helper and collection improvements. If you are running Laravel 11 on PHP 8.2+, the upgrade path is straightforward — but a few structural decisions deserve deliberate attention.


Typed Configuration Objects

The most architecturally interesting addition is first-class support for binding typed config objects into the service container. Instead of scattering config('services.stripe.key') calls throughout your codebase, you can now define a plain PHP object and register it once.

// app/Config/StripeConfig.php
readonly class StripeConfig
{
    public function __construct(
        public string $key,
        public string $webhookSecret,
        public bool $testMode,
    ) {}
}
// AppServiceProvider::register()
$this->app->singleton(StripeConfig::class, fn () => new StripeConfig(
    key: config('services.stripe.key'),
    webhookSecret: config('services.stripe.webhook_secret'),
    testMode: (bool) config('services.stripe.test_mode', false),
));

Now any class that type-hints StripeConfig receives a fully resolved, IDE-friendly object — no more string-keyed lookups, no more silent null surprises when a key is missing.

Testing Becomes Trivial

it('charges the card in test mode', function () {
    $this->app->instance(StripeConfig::class, new StripeConfig(
        key: 'sk_test_fake',
        webhookSecret: 'whsec_fake',
        testMode: true,
    ));

    // act and assert...
});

No more Config::set() scattered across test files.


The Slimmer Skeleton

Laravel 12 ships with far fewer stub files in a fresh laravel new project. Several files that previously lived in app/Http/Middleware/ are now consolidated or removed entirely, with their logic folded into the framework itself.

What is gone from the default skeleton:

  • TrimStrings, ConvertEmptyStringsToNull, and PreventRequestsDuringMaintenance middleware stubs — they still run, but you no longer own copies unless you publish them.
  • The app/Http/Kernel.php file is absent; middleware registration lives in bootstrap/app.php (introduced in Laravel 11, now the only way).

If your upgrade path involves a legacy Kernel.php, the migration is mechanical:

// bootstrap/app.php
return Application::configure(basePath: dirname(__DIR__))
    ->withMiddleware(function (Middleware $middleware) {
        $middleware->append(\App\Http\Middleware\MyCustomMiddleware::class);
        $middleware->remove(\Illuminate\Http\Middleware\TrimStrings::class);
    })
    ->create();

Collection and Helper Additions

collect()->intersectAssoc()

A long-requested method that compares both keys and values:

$a = collect(['color' => 'red', 'size' => 'M']);
$b = collect(['color' => 'red', 'size' => 'L']);

$a->intersectAssoc($b); // ['color' => 'red']

Str::chopStart() / Str::chopEnd()

Clean alternatives to ltrim/rtrim for specific substrings:

Str::chopStart('/api/v1/users', '/api'); // '/v1/users'
Str::chopEnd('report.csv.tmp', '.tmp'); // 'report.csv'

Upgrade Notes Worth Acting On

  1. PHP minimum is 8.2. Drop any 7.x/8.0/8.1 compatibility shims.
  2. Model::preventLazyLoading() is on by default in local. Audit your resources and Nova/Filament panels for N+1s before upgrading.
  3. assertJsonPath now validates strict types. Tests that previously passed with loose comparisons may fail — fix the assertions, not the strictness.
  4. Vite 6 is the default. If you pinned vite in package.json, bump it and review your vite.config.js for deprecated plugin options.

Key Takeaways

  • Typed config objects eliminate string-keyed config() calls and make test overrides explicit.
  • The slimmer skeleton reduces noise; understand which middleware moved into the framework before upgrading.
  • Str::chopStart/chopEnd and intersectAssoc are small but immediately useful.
  • preventLazyLoading being on by default in local is a gift — let it surface your N+1s now.
  • The upgrade from Laravel 11 is low-risk if you already adopted bootstrap/app.php middleware registration.

Found this useful?

Frequently Asked Questions

3 questions
Q01 Is Laravel 12 a long-term support release?
No. Laravel 12 follows the standard release cycle with 18 months of bug fixes and 2 years of security fixes. Only even-numbered releases on the LTS cadence (like Laravel 6 and 9) have received extended support historically, though the project has moved away from formal LTS designations.
Q02 Do typed config objects replace the config() helper entirely?
No. The config() helper still works and is appropriate for simple lookups. Typed config objects shine when multiple classes share the same configuration group, when you want IDE autocompletion, or when you need clean test overrides via app()->instance().
Q03 Will my existing Laravel 11 app break if lazy loading prevention is now on by default?
Only in the local environment, and only if you have genuine N+1 relationships being accessed without eager loading. It will throw a LazyLoadingViolationException. Fix the underlying queries with with() calls rather than disabling the guard.

Continue reading

More Articles

View all