Skip to content

[13.x] Fix DatabaseTransactionsManager::commit() return type - #62431

Merged
taylorotwell merged 2 commits into
laravel:13.xfrom
dhrupo:fix-transactions-manager-commit-return
Nov 12, 2026
Merged

taylorotwell merged 2 commits into
laravel:13.xfrom
dhrupo:fix-transactions-manager-commit-return

Conversation

@dhrupo

@dhrupo dhrupo commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

Follow-up to #60420, which added the Collection<int, DatabaseTransactionRecord> generic to the DatabaseTransactionsManager getters. commit() is still documented as returning array, but it returns the committed $forThisConnection collection, and only returns [] early when the callbacks should not run yet.

$manager->begin('default', 1);
get_class($manager->commit('default', 1, 0)); // Illuminate\Support\Collection

PHPStan (level 3) reports commit() should return array but returns Illuminate\Support\Collection<int, Illuminate\Database\DatabaseTransactionRecord>. Docblock only, no runtime change.

Description drafted with Claude Code.

* @param int $levelBeingCommitted
* @param int $newTransactionLevel
* @return array
* @return \Illuminate\Support\Collection<int, \Illuminate\Database\DatabaseTransactionRecord>|array{}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may be able to narrow this further down:

Suggested change
* @return \Illuminate\Support\Collection<int, \Illuminate\Database\DatabaseTransactionRecord>|array{}
* @return \Illuminate\Support\Collection<int, \Illuminate\Database\DatabaseTransactionRecord>|array{}
* @phpstan-return ($newTransactionLevel is 0 ? \Illuminate\Support\Collection<int, \Illuminate\Database\DatabaseTransactionRecord> : \Illuminate\Support\Collection<int, \Illuminate\Database\DatabaseTransactionRecord>|array{})

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, the early return [] can't happen when $newTransactionLevel is 0. Added it, thanks.

@taylorotwell
taylorotwell merged commit 20d231f into laravel:13.x Nov 12, 2026
62 checks passed
@dhrupo
dhrupo deleted the fix-transactions-manager-commit-return branch November 13, 2026 03:23
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.

3 participants