#2550·larastan

Database connection is not respected when inferring model properties

Author: gasaichandesuCreated Sep 15, 2026Updated Sep 15, 2026
Labelsbug
  • Larastan Version: 3.12.0
  • Laravel Version: 12.56.0

Description

Larastan appears to treat table names as globally unique across all configured migrations, ignoring the database connection used by Schema::connection().

This causes incorrect model property inference when the same table name exists on different connections at different points in migration history.

Laravel code where the issue was found

A table originally existed in the default application database:

php
Schema::create('subcontract_agreements', function (Blueprint $table): void {
    $table->id();
    $table->uuid('uuid');
});

Later, the table was moved into a separate module/database connection:

php
Schema::connection('subcontract_agreements')
    ->create('subcontract_agreements', function (Blueprint $table): void {
        $table->id();
        $table->uuid('uuid');
        $table->unsignedTinyInteger('version');
        $table->string('status');
    });

The old table in the default connection was then removed:

php
Schema::dropIfExists('subcontract_agreements');

The corresponding model uses the new connection:

php
abstract class Model extends EloquentModel
{
    protected $connection = 'subcontract_agreements';
}

class SubcontractAgreement extends Model
{
}

At runtime, this is valid and the subcontract_agreements table exists on the subcontract_agreements connection.

However, Larastan reports properties such as:

$subcontractAgreement->uuid;
$subcontractAgreement->version;
$subcontractAgreement->status;

as undefined.