Skip to content

[13.x] Respect child #[Connection] attribute over inherited $connection property - #62065

Merged
taylorotwell merged 1 commit into
laravel:13.xfrom
xurshudyan:connection-attribute-child-override
Oct 17, 2026
Merged

taylorotwell merged 1 commit into
laravel:13.xfrom
xurshudyan:connection-attribute-child-override

Conversation

@xurshudyan

Copy link
Copy Markdown
Contributor

When a base model has a $connection property and a child model sets its own connection with the #[Connection] attribute, the attribute just gets ignored and the child still uses the parent's connection:

abstract class BaseModel extends Model
{
    protected $connection = 'mysql';
}

#[Connection('reporting')]
class SalesReport extends BaseModel {}

(new SalesReport)->getConnectionName(); // 'mysql' instead of 'reporting'

No error, the queries just go to the wrong database. It's an easy one to run into when switching to attributes bit by bit, since the base model usually keeps the old property.

@taylorotwell
taylorotwell merged commit 4145fde into laravel:13.x Oct 17, 2026
64 checks passed
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