Skip to content

[12.x] Support Eloquent builders and relations as subqueries to update queries#58692

Merged
taylorotwell merged 1 commit into
laravel:12.xfrom
axlon:eloquent-subqueries
Feb 9, 2026
Merged

[12.x] Support Eloquent builders and relations as subqueries to update queries#58692
taylorotwell merged 1 commit into
laravel:12.xfrom
axlon:eloquent-subqueries

Conversation

@axlon

@axlon axlon commented Feb 8, 2026

Copy link
Copy Markdown
Contributor

This PR adds support for Eloquent\Builder and Relation in Query\Builder::update(), allowing for simpler update queries:

FooModel::where('...')->update([
-    'bar_id' => BarModel::where('...')->toBase()->select('id'),
+    'bar_id' => BarModel::where('...')->select('id'),
]);

If-condition was taken from:

if ($query instanceof self || $query instanceof EloquentBuilder || $query instanceof Relation) {

@taylorotwell taylorotwell merged commit 57eb459 into laravel:12.x Feb 9, 2026
72 checks passed
@axlon axlon deleted the eloquent-subqueries branch March 4, 2026 19:25
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