Skip to content

Commit 676fabc

Browse files
author
Ronald A Richardson
committed
fix: remove connection-overriding constructors from Model and Setting
The constructors in Model.php and Setting.php both set: $this->connection = config('fleetbase.connection.db', 'mysql'); On main, the wrong config key ('fleetbase.db.connection') returned null, making the constructors effectively no-ops — models without an explicit $connection declaration correctly fell back to database.default, which sandbox mode switches to 'sandbox'. The typo fix made the constructors actively harmful by always forcing 'mysql', breaking sandbox switching for every model that does not declare its own $connection. The correct fix is to remove both constructors entirely: - Models that declare $connection = 'mysql' (User, Company, Invite, etc.) have that value set by PHP at class instantiation — no constructor needed. - Models without an explicit $connection (ApiCredential, CompanyUser, etc.) correctly inherit null from Eloquent and follow database.default, which is 'sandbox' in sandbox mode and 'mysql' otherwise. The Invite model is handled separately via getConnectionName() override.
1 parent e1814fc commit 676fabc

2 files changed

Lines changed: 0 additions & 28 deletions

File tree

src/Models/Model.php

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,6 @@ class Model extends EloquentModel
3030
public const UUID_COLUMN = 'uuid';
3131
public const PUBLIC_ID_COLUMN = 'public_id';
3232

33-
/**
34-
* Create a new instance of the model.
35-
*
36-
* @param array $attributes the attributes to set on the model
37-
*
38-
* @return void
39-
*/
40-
public function __construct(array $attributes = [])
41-
{
42-
parent::__construct($attributes);
43-
44-
$this->connection = config('fleetbase.connection.db', 'mysql');
45-
}
46-
4733
/**
4834
* The primary key for the model.
4935
*

src/Models/Setting.php

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,6 @@ class Setting extends EloquentModel
2020
use Searchable;
2121
use Filterable;
2222

23-
/**
24-
* Create a new instance of the model.
25-
*
26-
* @param array $attributes the attributes to set on the model
27-
*
28-
* @return void
29-
*/
30-
public function __construct(array $attributes = [])
31-
{
32-
parent::__construct($attributes);
33-
34-
$this->connection = config('fleetbase.connection.db', 'mysql');
35-
}
36-
3723
/**
3824
* No timestamp columns.
3925
*

0 commit comments

Comments
 (0)