From f03c61141f336e8c4d2ffe44a4f2dce7e4786225 Mon Sep 17 00:00:00 2001 From: Jure Knezovic Date: Fri, 19 Jun 2026 11:54:23 +0200 Subject: [PATCH 1/4] feat(schema.org): add PostalAddress DTO with schema.org support Introduce `PostalAddress` data transfer object to standardize schema.org postal address representation. Added `toArray` and `toJsonLd` methods for rendering address data as fragments or standalone JSON-LD. Updated the `Address` model with a `toSchemaOrg` method to generate `PostalAddress` instances. Includes tests and documentation updates. --- README.md | 26 +++++++++++++ src/App/Data/PostalAddress.php | 46 +++++++++++++++++++++++ src/App/Models/Address.php | 24 ++++++++++++ tests/Feature/AddressableTest.php | 24 ++++++++++++ tests/Unit/PostalAddressTest.php | 62 +++++++++++++++++++++++++++++++ 5 files changed, 182 insertions(+) create mode 100644 src/App/Data/PostalAddress.php create mode 100644 tests/Unit/PostalAddressTest.php diff --git a/README.md b/README.md index 1e5fd40..a9b4be6 100644 --- a/README.md +++ b/README.md @@ -189,6 +189,32 @@ The columns map to [schema.org/PostalAddress](https://schema.org/PostalAddress): `latitude` / `longitude` are stored as `decimal(10,8)` / `decimal(11,8)` and cast to `decimal:8`. +### Emitting a `PostalAddress` + +`$address->toSchemaOrg()` returns a `PostalAddress` DTO that renders to either a +PHP array or a JSON-LD string: + +```php +$address->toSchemaOrg()->toArray(); +// [ +// '@type' => 'PostalAddress', +// 'streetAddress' => 'Pariser Platz 1', +// 'postalCode' => '10117', +// 'addressLocality' => 'Berlin', +// 'addressCountry' => 'DE', +// // null fields omitted; no '@context' +// ] + +$address->toSchemaOrg()->toJsonLd(); +// {"@context":"https://schema.org","@type":"PostalAddress","streetAddress":"Pariser Platz 1",…} +``` + +`toArray()` is a **fragment** (`@type`, no `@context`) — nest it inside a parent +entity such as `Organization`/`Person`. `toJsonLd()` is a **standalone** document +(includes `@context`) — drop it straight into a `