GeoArea Service
The GeoArea service manages geo areas. A geo area is a reusable grouping of multiple locations.
Geo areas support:
- Soft delete / restore / force delete
- Status toggling
- Attaching and syncing locations (via
HasLocationin multiple mode)
Facade
use JobMetric\Location\Facades\GeoArea;
Basic CRUD Operations
Store
Create a new geo area. translation is required.
$response = GeoArea::store([
'translation' => [
'en' => [
'name' => 'Tehran Zone',
'description' => 'All supported districts in Tehran.',
],
],
'status' => true,
'locations' => [
['country_id' => 1, 'province_id' => 10],
['country_id' => 1, 'province_id' => 10, 'city_id' => 120],
],
]);
Notes:
locationsis optional; if present, the service will attach locations after store.- Duplicate locations in the payload are rejected by the request validation.
Show
$response = GeoArea::show($geoAreaId);
// With relations (typical)
$response = GeoArea::show($geoAreaId, ['locationRelations.location']);
Update
When locations is provided on update, the service will:
- Detach all existing locations
- Attach the provided locations
$response = GeoArea::update($geoAreaId, [
'translation' => [
'en' => [
'name' => 'Tehran Zone (Updated)',
'description' => 'Updated coverage.',
],
],
'locations' => [
['country_id' => 1, 'province_id' => 10, 'city_id' => 120, 'district_id' => 900],
],
]);
Destroy / Restore / Force Delete
$response = GeoArea::destroy($geoAreaId);
$response = GeoArea::restore($geoAreaId);
$response = GeoArea::forceDelete($geoAreaId);
Toggle Status
$response = GeoArea::toggleStatus($geoAreaId);
Querying
// List only active geo areas
$response = GeoArea::paginate(15, ['status' => true]);