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.
Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Clear out junk files and repair common Windows errors3Scan for outdated or missing drivers - takes under a minuteHow 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.
#1 Best Overall
| 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
arrayorjson, the Laravel News example encodes the structure withjson_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.
Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchPC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Does 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.
Rank #3
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.
Rank #4
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.
Quick Recap
Best Value
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.




