Commit 3865ec7
Ronald A Richardson
fix: remove Model/Setting constructors that broke sandbox connection switching
The constructors introduced in both Model.php and Setting.php called:
$this->connection = config('fleetbase.db.connection');
This config key does not exist (correct key: fleetbase.connection.db),
so config() returned null, overwriting the child class's declared
$connection property on every instantiation.
A subsequent attempt to guard with empty($this->connection) overcorrected
in the opposite direction: models without an explicit $connection
declaration (the sandbox-aware ones) were always resolved to 'mysql',
ignoring the database.default switch that sandbox mode sets to 'sandbox'.
The correct fix is simply to remove both constructors entirely:
- PHP initialises class property declarations before any constructor runs,
so models that explicitly declare $connection = 'mysql' (Invite, Setting,
User, Company, Role, Permission, etc.) will always use that value — no
constructor logic needed.
- Models that do NOT declare $connection (ApiCredential, CompanyUser,
Activity, etc.) correctly inherit null from Eloquent's base class, which
causes Laravel to resolve the connection from config('database.default').
In sandbox mode that is 'sandbox'; in normal mode it is 'mysql'. This is
exactly the intended behaviour.
No functional change for any model — this purely restores the correct
connection resolution that existed before the constructors were added.1 parent 561d3cd commit 3865ec7
2 files changed
Lines changed: 0 additions & 50 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | 33 | | |
63 | 34 | | |
64 | 35 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | 23 | | |
45 | 24 | | |
46 | 25 | | |
| |||
0 commit comments