Zum Inhalt springen

Laravel Framework Updates & Release Notes

Einträge
234
Quellen
1
Zuletzt aktualisiert

Folge Laravel Framework, um die Release Notes in deinen Feed zu holen.

Laravel Framework von Laravel

Laravel Framework 12.x: makeMany-Methode für Factories

Die neue Factory-Methode makeMany() erzeugt mehrere Modellinstanzen im Speicher, ohne sie zu speichern.

Pull request by @jackbayliss

makeMany() gives you a clean, expressive way to generate multiple in-memory model instances without persisting anything. It's ideal for tests, previews, and shaping data before a write.

$users = User::factory()->makeMany(3);

$payload = $users->map->only(['name', 'email']);

Originalquelle(öffnet in neuem Tab)Problem melden

Laravel Framework von Laravel

Laravel Framework 12.x: Closures für Werte in firstOrCreate und createOrFirst

firstOrCreate und createOrFirst akzeptieren nun Closures für Werte, die nur berechnet werden, wenn der Datensatz tatsächlich angelegt wird.

Pull request by @gcavanunez

You can now lazily compute attribute values only when a record is actually being created. That means fewer unnecessary queries and less wasted work when the model already exists.

$location = Location::firstOrCreate(
    ['address' => $address],
    fn () => ['coordinates' => Geocoder::resolve($address)],
);

Originalquelle(öffnet in neuem Tab)Problem melden

Laravel Framework von Laravel

Laravel 12.x: Methode afterSending für Notifications

Notifications unterstützen jetzt die Methode afterSending(), die nach dem Versand der Notification ausgeführt wird, etwa für Audit-Logging, Metriken oder Aufräumarbeiten.

Pull request by @gdebrauwer

afterSending() lets you hook into the lifecycle after a notification is dispatched, which is perfect for audit logging, metrics, or cleanup work without cluttering your notification channels.

class BookingNotification extends Notification
{
    public function __construct(
		public Booking $booking;
	) {
        //
	}

	public function via()
	{
		return ['mail'];
	}

	public function toMail()
	{
		// ...
	}

	public function afterSending($notifiable, $channel, $response)
	{
		$this->booking->update(['notified_at' => now()]);
	}
}

Originalquelle(öffnet in neuem Tab)Problem melden

Laravel Framework von Laravel

Laravel 12.x: whenFails und whenPasses im Validator

Der Validator bietet die neuen Methoden whenFails und whenPasses, nützlich für Validierungen außerhalb des Request-Zyklus.

Pull request by @gdebrauwer

These helpers are particularly useful when you use the validator to validate data outside the request cycle where the error would not get picked up automatically by the HTTP handler.

Validator::make(
    ['file' => $file],
    ['file' => 'required|image|dimensions:min_width=100,min_height=200']
)->whenFails(function () {
    throw new InvalidArgumentException('Provided file is invalid');
});

Originalquelle(öffnet in neuem Tab)Problem melden

Laravel Framework von Laravel

Laravel 12.x: withoutHeader-Methode für Response

Mit der neuen Methode withoutHeader() lassen sich Header, etwa geerbte Caching- oder Debug-Header, aus einer Response entfernen.

Pull request by @miladev95

Removing headers is now straightforward with withoutHeader(), which is handy when you need to strip inherited headers (like caching or debug headers) before returning a response.

return response($content)->withoutHeader('X-Debug');

Originalquelle(öffnet in neuem Tab)Problem melden

Laravel Framework von Laravel

Laravel 12.x: InteractsWithData::clamp() hinzugefügt

Der Trait InteractsWithData enthält die neue Methode clamp(), mit der numerische Eingabewerte auf einen Wertebereich mit Standardwert begrenzt werden können.

Pull request by @cosmastech

A clamp() method has been added to the InteractsWithData trait, giving you a tidy way to bound numeric input values, which is great for pagination, limits, sliders, and any user-controlled numbers.

// Instead of:
/** @var int<PHP_INT_MIN, PHP_INT_MAX> $perPage */
$perPage = request()->integer('per_page', 50);

// You can now do:
/** @var int<1, 100> $perPage */
$perPage = request()->clamp('per_page', 1, 100, 50);

Originalquelle(öffnet in neuem Tab)Problem melden

Laravel Framework von Laravel

Laravel 12.x: Neue Direktive @includeIsolated

Die neue Blade-Direktive @includeIsolated bindet Partials isoliert ein, sodass sie nur explizit übergebene Variablen erhalten.

Pull request by @KennedyTedesco

When you need to reuse a partial without accidentally leaking variables in (or out), @includeIsolated gives you a clean, predictable boundary - great for shared UI components and emails where "mystery data" can be costly to debug.

{{-- Only receives what you pass explicitly --}}
@includeIsolated("partials.alert", ["type" => "success", "message" => $message])

Originalquelle(öffnet in neuem Tab)Problem melden

Laravel Framework von Laravel

Laravel 12.x: Cache::withoutOverlapping() ergänzt

Cache::withoutOverlapping() wrappt Cache::lock()->block() und verhindert überlappende Ausführungen mit weniger Boilerplate.

Pull request by @mathiasgrimm

This adds a tidy, expressive wrapper around cache locks, so you can prevent overlapping work with less boilerplate. Perfect for cron jobs, report generation, and any "only one at a time" tasks.

Cache::withoutOverlapping('reports:daily')
    ->block(10, function () {
        // This work will not run concurrently.
        GenerateDailyReport::run();
    });

Originalquelle(öffnet in neuem Tab)Problem melden

Laravel Framework von Laravel

Laravel 12.x: Vector Embeddings in der Datenbank

Laravel erweitert seine Vector-Fähigkeiten um Unterstützung für Vector Embeddings in der Datenbank.

Pull request by @taylorotwell

This work moves Laravel's "vector" capabilities forward, helping set the stage for richer integrations and smoother workflows when dealing with embeddings and similarity search. If you're exploring AI-powered features, this one's for you.

Originalquelle(öffnet in neuem Tab)Problem melden

Laravel Framework von Laravel

Laravel 12.x: Neue Methode Collection::containsManyItems()

Die neue Methode containsManyItems prüft, ob eine Collection zwei oder mehr Elemente enthält, als Ergänzung zu containsOneItem.

Pull request by @stevebauman

A new containsManyItems method was added to complement the existing containsOneItem, enabling you to do a quick check to see if a collection contains two or more items.

match (true) {
    $collection->isEmpty() => '...',
    $collection->containsOneItem() => '...',
    $collection->containsManyItems() => '...',
};

Originalquelle(öffnet in neuem Tab)Problem melden

Laravel Framework von Laravel

Laravel 12.x: JSON:API-Resource

Laravel unterstützt jetzt JSON:API-Resources, um standardkonforme APIs mit einheitlicher Struktur einfacher bereitzustellen.

Pull request by @crynobone

This introduces JSON:API resource support, making it easier to ship standards-compliant APIs with consistent structure across teams and services. If you're standardizing responses (or integrating with clients that expect JSON:API), this helps reduce custom formatting and makes your API surface more predictable.

Originalquelle(öffnet in neuem Tab)Problem melden

Laravel Framework von Laravel

Laravel 12.x: BackedEnum als Session-Keys

Backed Enums können nun als Session-Keys verwendet werden.

Pull request by @ahinkle

You can now use backed enums as session keys, which keeps key names centralized and typo-proof, especially helpful in larger apps where session keys tend to spread over time.

enum CheckoutSession: string
{
    case Cart = 'checkout.cart';
    case ShippingAddress = 'checkout.shipping_address';
    case PaymentMethod = 'checkout.payment_method';
}

session()->put(CheckoutSession::Cart, $items);
session()->get(CheckoutSession::Cart);

Originalquelle(öffnet in neuem Tab)Problem melden

Laravel Framework von Laravel

Laravel 12.x: BackedEnum für Cache-Keys erlaubt

Backed Enums lassen sich nun auch als Cache-Keys verwenden.

Pull request by @jackbayliss

Same productivity boost, now for cache: backed enums can be used as cache keys, helping you standardize key naming and avoid subtle collisions. Great fit for teams that want a single source of truth for cache identifiers.

enum CacheKey: string
{
    case Settings = 'settings.global';
}

Cache::put(CacheKey::Settings, $settings, now()->addHour());

$settings = Cache::get(CacheKey::Settings);

Originalquelle(öffnet in neuem Tab)Problem melden

Laravel Framework von Laravel

Laravel 12.x: Flag --readable für env:encrypt

Das neue Flag --readable bei env:encrypt hält Schlüsselnamen in der verschlüsselten Env-Ausgabe sichtbar und schützt weiterhin die Werte.

Pull request by @mathiasgrimm

A practical quality-of-life improvement: --readable makes encrypted env output easier to audit by keeping key names visible, which helps during reviews and incident response while still protecting secret values. If you're hardening deployments, this pairs nicely with Laravel's environment encryption workflow.

php artisan env:encrypt --readable

Originalquelle(öffnet in neuem Tab)Problem melden

Laravel Framework von Laravel

Laravel 12.x: @includeIsolated-Direktive für Blade

Die neue Blade-Direktive @includeIsolated bindet Partials isoliert ein, sodass sie nur explizit übergebene Daten erhalten und keine Variablen hinein- oder herausgelangen.

Pull request by @KennedyTedesco

When you need to reuse a partial without accidentally leaking variables in (or out), @includeIsolated gives you a clean, predictable boundary - great for shared UI components and emails where "mystery data" can be costly to debug.

{{-- Only receives what you pass explicitly --}}
@includeIsolated("partials.alert", ["type" => "success", "message" => $message])

Originalquelle(öffnet in neuem Tab)Problem melden

Laravel Framework von Laravel

Laravel 12.x: Cache::withoutOverlapping() ergänzt

Cache::withoutOverlapping() ist ein neuer Wrapper um Cache::lock()->block(), der überlappende Ausführungen mit weniger Code verhindert.

Pull request by @mathiasgrimm

This adds a tidy, expressive wrapper around cache locks, so you can prevent overlapping work with less boilerplate. Perfect for cron jobs, report generation, and any "only one at a time" tasks.

Cache::withoutOverlapping('reports:daily')
    ->block(10, function () {
        // This work will not run concurrently.
        GenerateDailyReport::run();
    });

Originalquelle(öffnet in neuem Tab)Problem melden

Laravel Framework von Laravel

Laravel 12.x: Collection::containsManyItems()

Die neue Collection-Methode containsManyItems prüft, ob eine Collection zwei oder mehr Elemente enthält, und ergänzt containsOneItem.

Pull request by @stevebauman

A new containsManyItems method was added to complement the existing containsOneItem, enabling you to do a quick check to see if a collection contains two or more items.

match (true) {
    $collection->isEmpty() => '...',
    $collection->containsOneItem() => '...',
    $collection->containsManyItems() => '...',
};

Originalquelle(öffnet in neuem Tab)Problem melden

Laravel Framework von Laravel

Laravel 12.x: JSON:API Resource

Laravel unterstützt nun JSON:API Resources, um standardkonforme APIs mit konsistenter Struktur zu erstellen.

Pull request by @crynobone

This introduces JSON:API resource support, making it easier to ship standards-compliant APIs with consistent structure across teams and services. If you're standardizing responses (or integrating with clients that expect JSON:API), this helps reduce custom formatting and makes your API surface more predictable.

Originalquelle(öffnet in neuem Tab)Problem melden

Laravel Framework von Laravel

Laravel 12.x: BackedEnum als Session-Keys

Backed Enums können jetzt als Session-Keys verwendet werden.

Pull request by @ahinkle

You can now use backed enums as session keys, which keeps key names centralized and typo-proof, especially helpful in larger apps where session keys tend to spread over time.

enum CheckoutSession: string
{
    case Cart = 'checkout.cart';
    case ShippingAddress = 'checkout.shipping_address';
    case PaymentMethod = 'checkout.payment_method';
}

session()->put(CheckoutSession::Cart, $items);
session()->get(CheckoutSession::Cart);

Originalquelle(öffnet in neuem Tab)Problem melden

Laravel Framework von Laravel

Laravel 12.x: BackedEnum für Cache-Keys erlaubt

Backed Enums lassen sich nun auch als Cache-Keys verwenden.

Pull request by @jackbayliss

Same productivity boost, now for cache: backed enums can be used as cache keys, helping you standardize key naming and avoid subtle collisions. Great fit for teams that want a single source of truth for cache identifiers.

enum CacheKey: string
{
    case Settings = 'settings.global';
}

Cache::put(CacheKey::Settings, $settings, now()->addHour());

$settings = Cache::get(CacheKey::Settings);

Originalquelle(öffnet in neuem Tab)Problem melden