Skip to content

Commit d249909

Browse files
TinyMemoriaBoy132
andauthored
Delete subdomain on server delete (#92)
* delete subdomain on server delete * log the exception * pint fixes * Apply suggestion from @Boy132 Co-authored-by: Boy132 <Boy132@users.noreply.github.com> --------- Co-authored-by: Boy132 <Boy132@users.noreply.github.com>
1 parent e6a2910 commit d249909

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

subdomains/src/Providers/SubdomainsPluginProvider.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use App\Models\Server;
88
use Boy132\Subdomains\Filament\Admin\Resources\Servers\RelationManagers\SubdomainRelationManager;
99
use Boy132\Subdomains\Models\Subdomain;
10+
use Exception;
1011
use Illuminate\Support\Facades\Http;
1112
use Illuminate\Support\ServiceProvider;
1213

@@ -32,5 +33,16 @@ public function boot(): void
3233
);
3334

3435
Server::resolveRelationUsing('subdomains', fn (Server $server) => $server->hasMany(Subdomain::class, 'server_id', 'id'));
36+
37+
Server::deleting(function (Server $server) {
38+
/** @phpstan-ignore property.notFound */
39+
foreach ($server->subdomains as $subdomain) {
40+
try {
41+
$subdomain->delete();
42+
} catch (Exception $exception) {
43+
report($exception);
44+
}
45+
}
46+
});
3547
}
3648
}

0 commit comments

Comments
 (0)