diff --git a/app/Services/Locations/LocationDeletionService.php b/app/Services/Locations/LocationDeletionService.php index 628dd82d3..3d8e649ae 100644 --- a/app/Services/Locations/LocationDeletionService.php +++ b/app/Services/Locations/LocationDeletionService.php @@ -24,11 +24,9 @@ class LocationDeletionService */ public function handle(Location|int $location): ?int { - $location = ($location instanceof Location) ? $location->id : $location; + $location = ($location instanceof Location) ? $location : $location->id; - Assert::integerish($location, 'First argument passed to handle must be numeric or an instance of ' . Location::class . ', received %s.'); - - $count = $this->nodeRepository->findCountWhere([['location_id', '=', $location]]); + $count = $location->nodes()->count(); if ($count > 0) { throw new HasActiveNodesException(trans('exceptions.locations.has_nodes')); } diff --git a/app/Services/Locations/LocationUpdateService.php b/app/Services/Locations/LocationUpdateService.php index c394503ca..ed5f0cdb8 100644 --- a/app/Services/Locations/LocationUpdateService.php +++ b/app/Services/Locations/LocationUpdateService.php @@ -12,8 +12,13 @@ class LocationUpdateService */ public function handle(Location|int $location, array $data): Location { - $location = ($location instanceof Location) ? $location->id : $location; + /** @var Location $location */ + if (is_int($location)) { + $location = Location::query()->findOrFail($location); + } - return $location->update($data); + $location->update($data); + + return $location; } }