misc_pterodactyl-panel/app/Services/Locations/LocationDeletionService.php

28 lines
709 B
PHP
Raw Normal View History

<?php
namespace Pterodactyl\Services\Locations;
2018-01-04 03:14:53 +00:00
use Pterodactyl\Models\Location;
use Pterodactyl\Exceptions\Service\Location\HasActiveNodesException;
class LocationDeletionService
{
/**
* Delete an existing location.
*
2022-10-24 02:17:24 +00:00
* @throws HasActiveNodesException
*/
public function handle(Location|int $location): ?int
{
2022-10-24 02:17:24 +00:00
/** @var Location $location */
$location = ($location instanceof Location) ? $location : Location::query()->findOrFail($location);
2022-10-24 02:17:24 +00:00
$count = $location->nodes()->count();
if ($count > 0) {
throw new HasActiveNodesException(trans('exceptions.locations.has_nodes'));
}
2022-10-24 02:17:24 +00:00
return $location->delete();
}
}