Skip to content

Commit a77e1f4

Browse files
committed
fix(models): replace forceCreate with forceFill+save pattern
Replaces Model::forceCreate([...]) calls with (new Model)->forceFill([...])->save() across SettingsBackup, Server, and User models to avoid bypassing Eloquent model event lifecycle during record creation.
1 parent 1a603a1 commit a77e1f4

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

app/Livewire/SettingsBackup.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ public function addCoolifyDatabase()
8383
$postgres_password = $envs['POSTGRES_PASSWORD'];
8484
$postgres_user = $envs['POSTGRES_USER'];
8585
$postgres_db = $envs['POSTGRES_DB'];
86-
$this->database = StandalonePostgresql::forceCreate([
86+
$this->database = new StandalonePostgresql;
87+
$this->database->forceFill([
8788
'id' => 0,
8889
'name' => 'coolify-db',
8990
'description' => 'Coolify database',
@@ -94,6 +95,7 @@ public function addCoolifyDatabase()
9495
'destination_type' => StandaloneDocker::class,
9596
'destination_id' => 0,
9697
]);
98+
$this->database->save();
9799
$this->backup = ScheduledDatabaseBackup::create([
98100
'id' => 0,
99101
'enabled' => true,

app/Models/Server.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,28 +143,28 @@ protected static function booted()
143143
}
144144
});
145145
static::created(function ($server) {
146-
ServerSetting::forceCreate([
146+
ServerSetting::create([
147147
'server_id' => $server->id,
148148
]);
149149
if ($server->id === 0) {
150150
if ($server->isSwarm()) {
151-
SwarmDocker::forceCreate([
151+
(new SwarmDocker)->forceFill([
152152
'id' => 0,
153153
'name' => 'coolify',
154154
'network' => 'coolify-overlay',
155155
'server_id' => $server->id,
156-
]);
156+
])->save();
157157
} else {
158-
StandaloneDocker::forceCreate([
158+
(new StandaloneDocker)->forceFill([
159159
'id' => 0,
160160
'name' => 'coolify',
161161
'network' => 'coolify',
162162
'server_id' => $server->id,
163-
]);
163+
])->saveQuietly();
164164
}
165165
} else {
166166
if ($server->isSwarm()) {
167-
SwarmDocker::forceCreate([
167+
SwarmDocker::create([
168168
'name' => 'coolify-overlay',
169169
'network' => 'coolify-overlay',
170170
'server_id' => $server->id,

app/Models/User.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ protected static function boot()
9898
$team['id'] = 0;
9999
$team['name'] = 'Root Team';
100100
}
101-
$new_team = Team::forceCreate($team);
101+
$new_team = (new Team)->forceFill($team);
102+
$new_team->save();
102103
$user->teams()->attach($new_team, ['role' => 'owner']);
103104
});
104105

@@ -201,7 +202,8 @@ public function recreate_personal_team()
201202
$team['id'] = 0;
202203
$team['name'] = 'Root Team';
203204
}
204-
$new_team = Team::forceCreate($team);
205+
$new_team = (new Team)->forceFill($team);
206+
$new_team->save();
205207
$this->teams()->attach($new_team, ['role' => 'owner']);
206208

207209
return $new_team;

0 commit comments

Comments
 (0)