Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
Skip to content
World desk4 min

Laravel Eloquent Defaults: What the Reported API Lets You Set

Laravel’s reported Eloquent defaults() method supports runtime model defaults, but its release status, precedence rules, raw values, and version-specific adoption path matter.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The reported Laravel 14 defaults() method gives Eloquent models a place to define defaults that depend on runtime values, such as configuration or the current time. It is not yet safe to treat the API as final: Laravel News reported on October 1, 2026 that the change had been merged into Laravel’s master branch and could change before Laravel 14 is released. Laravel’s official release notes identify Laravel 13 as the released major version.

What defaults() is for

Eloquent’s $attributes property works well for fixed defaults. But a property cannot call config(), evaluate a feature flag, or calculate a value with now(). The reported method provides a code-based alternative: define a protected defaults(): array method on the model and return the values that should be present when it is constructed.

As an Amazon Associate I earn from qualifying purchases.

Laravel News describes a subscription-model example that returns cancelled, trial_days, and expires_at, with the trial duration selected from a feature flag and the expiry calculated using configuration. These are illustrative source examples, not independently tested results.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How defaults interact with other attribute values

In the implementation described by Laravel News, precedence follows the order in which values are applied: property defaults first, method defaults next, and caller-supplied values last. That means explicit input takes priority.

Source When it applies Which value wins?
$attributes Fixed values declared on the model Overridden by a matching value from defaults() or caller input
defaults() Values computed when the model is constructed Overrides a matching $attributes value; caller input can override it
Construction, create(), or fill() input Values supplied by the caller Wins over either kind of model default

The report says method defaults are merged before Eloquent synchronizes original attributes. Consequently, a defaulted value does not make a newly constructed model dirty merely by existing, while it can still be persisted on insertion like a value supplied through $attributes.

Return storage-ready values

The reported implementation treats values returned by defaults() as raw; it does not run them through casts or mutators. Return the representation expected for storage rather than assuming Eloquent will transform a PHP value for you.

  • For an attribute stored as JSON and cast to array or json, the Laravel News example encodes the structure with json_encode. Returning a PHP array directly can fail when the cast later expects a JSON string.
  • For a computed date, the example formats it as a database-style datetime string.

Check each returned value against the column representation and the model’s casts before adopting the pattern.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Does defaults() run when a database row is loaded?

According to the feature report, yes: the method runs each time an Eloquent model instance is constructed, including during database hydration. Values from the retrieved row then replace the defaults. Therefore, a method that performs expensive work or has side effects may do so for every hydrated row; that is a performance implication of the reported invocation behavior, not a measured benchmark.

Which Laravel version has the feature?

Version context matters because two distinct paths have been reported. On October 1, 2026, Laravel News said the Laravel 14 change was merged into master in pull request #61688 and warned it could change before release. Laravel’s official release notes list Laravel 13 as released on March 17, 2026. Do not assume the Laravel 14 implementation described here is a released API.

A separate Laravel News report dated October 7, 2026 describes an opt-in HasDefaultAttributes trait implementation in Laravel 13.35. It is not the same adoption path as the reported Laravel 14 behavior: the trait must be used explicitly, and is described as avoiding effects on models that already have a method named defaults(). Before relying on a version-specific example, check the installed framework release and its implementation.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Choosing between $attributes and defaults()

Consideration $attributes Reported defaults()
Best fit Fixed values declared on the model Values that need runtime computation, such as configuration or feature-flag decisions
Value handling Uses the conventional model attribute declaration; check normal cast behavior for the installed version Reported values are raw and must be returned in storage-ready form
Caller overrides Caller input can override the property value Caller input also wins over the method’s value
Compatibility check No defaults() method-name collision implied Check for existing methods with this name and confirm the framework version or trait path

Laravel’s Eloquent documentation on default attribute values covers the existing $attributes approach. For fixed values, it remains the straightforward choice; use a runtime method only where the value genuinely needs computation.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Upgrade checks

  • Search models and traits for existing methods named defaults(). The reported Laravel 14 constructor invokes a method with that name, so an unrelated method may conflict.
  • Confirm whether the target application is using the released Laravel 13 line, the reported Laravel 13.35 opt-in trait, or a future Laravel 14 release. Do not apply the trait path as if it were the Laravel 14 default behavior.
  • Inspect casts and mutators for each value returned. Under the reported behavior, raw values are not converted by them.
  • If the method does runtime work, account for the fact it is also invoked when models are hydrated from database rows.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.