Skip to main content

StoreAddressRequest

Form request class for validating Address creation data.

Namespace

JobMetric\Location\Http\Requests\Address\StoreAddressRequest

Overview

This request validates the address payload including:

  • Required geography fields: country_id, province_id, city_id
  • Address object keys whitelist (blvd, street, alley, number, floor, unit)
  • Optional info keys whitelist (mobile_prefix, mobile, name, landline, notes)

Owner fields (owner_type, owner_id) are validated by the Address service.

Validation Rules

Required location fields

FieldRule
country_idrequired|integer|exists:{countries},id
province_idrequired|integer|exists:{provinces},id
city_idrequired|integer|exists:{cities},id

Optional location field

FieldRule
district_idnullable|integer|exists:{districts},id

Address object

FieldRule
addressrequired|array (with allowed keys validation)
address.blvdnullable|string|max:255
address.streetnullable|string|max:255
address.alleynullable|string|max:255
address.numbernullable|string|max:50
address.floornullable|string|max:50
address.unitnullable|string|max:50

Optional fields

FieldRule
postcodenullable|string|max:20
latnullable|string|max:20
lngnullable|string|max:20
infonullable|array (with allowed keys validation)
info.mobile_prefixnullable|string|max:20
info.mobilenullable|string|max:50
info.namenullable|string|max:255
info.landlinenullable|string|max:50
info.notesnullable|string

Usage Example

use JobMetric\Location\Facades\Address;

$response = Address::store([
'owner_type' => \App\Models\User::class,
'owner_id' => 1,

'country_id' => 1,
'province_id' => 10,
'city_id' => 120,
'district_id' => 900,

'address' => [
'street' => 'Valiasr St',
'number' => '12',
],
'postcode' => '1234567890',
'info' => [
'name' => 'John Doe',
'mobile_prefix' => '+98',
'mobile' => '9120000000',
'notes' => 'Leave at reception',
],
]);