Skip to content

Conversation

@macaws
Copy link

@macaws macaws commented Oct 31, 2025

This is a resubmission of PR #56540, previously closed as a breaking change for Laravel 12.x. Proposing for Laravel 13.

Problem:

The AsFluent cast returns null when a database column is null, requiring null checks:

$user->preferences->get('theme'); // Crashes if preferences is null
$user->preferences?->get('theme'); // Current workaround - seems out of character for "Fluent"

Solution:

Always return a Fluent instance, even when the column is null:

$user->preferences->get('theme'); // Works safely, returns null if empty

This is especially useful for JSON columns in MySQL where default values cannot be set at the database level.

Breaking Change:

Code that explicitly checks for null to determine if a column was set will break. Acceptable for a major version release.

@taylorotwell
Copy link
Member

I don't think the breaking change is worth it to be honest. You can write a custom cast for this behavior if you want!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants