PHPackages                             helsingborg-stad/schema-org - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. helsingborg-stad/schema-org

AbandonedArchivedLibrary

helsingborg-stad/schema-org
===========================

A fluent builder Schema.org types and ld+json generator

1.4.0(1y ago)0456↓100%MITPHPPHP ^8.0CI passing

Since Mar 19Pushed 1y agoCompare

[ Source](https://github.com/helsingborg-stad/schema-org)[ Packagist](https://packagist.org/packages/helsingborg-stad/schema-org)[ Docs](https://github.com/spatie/schema-org)[ Fund](https://spatie.be/open-source/support-us)[ GitHub Sponsors](https://github.com/spatie)[ RSS](/packages/helsingborg-stad-schema-org/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (5)Dependencies (7)Versions (6)Used By (0)

A Fluent Builder For Schema.org Types And ld+json Generator
===========================================================

[](#a-fluent-builder-for-schemaorg-types-and-ldjson-generator)

**Note:** This fork includes types and extensions defined in the Municipio schema definition available at .

[![Latest Version on Packagist](https://camo.githubusercontent.com/b58f4230d2d902125bca56251d64c5cb1db9c0d93b102a05e43d4d96f3e45cf8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7370617469652f736368656d612d6f72672e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/schema-org)[![MIT License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![GitHub Workflow Status](https://camo.githubusercontent.com/47d35c208d19a2af16bea0268ee0e3ba429c3306b76ad070c5b46b43a34c7219/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f7370617469652f736368656d612d6f72672f72756e2d74657374733f7374796c653d666c61742d737175617265266c6f676f436f6c6f723d7768697465266c6f676f3d676974687562266c6162656c3d5465737473)](https://github.com/spatie/schema-org/actions?query=workflow%3Arun-tests)[![StyleCI](https://camo.githubusercontent.com/3db9382c3ef627c8332ac6509396b0c96983540bf4007bdc320936ca0cae9d57/68747470733a2f2f7374796c6563692e696f2f7265706f732f37343638343039362f736869656c643f6272616e63683d6d6173746572)](https://styleci.io/repos/74684096)[![Total Downloads](https://camo.githubusercontent.com/331734c9e34625906c26d0b240cabb0f76c9e434657ba7b983b174e32e7ca60b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7370617469652f736368656d612d6f72672e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/schema-org)

`spatie/schema-org` provides a fluent builder for **all** Schema.org types and their properties. The code in `src` is generated from Schema.org's [JSON-LD standards file](https://raw.githubusercontent.com/schemaorg/schemaorg/main/data/releases/13.0/schemaorg-all-https.jsonld), so it provides objects and methods for the entire core vocabulary. The classes and methods are also fully documented as a quick reference.

```
use Spatie\SchemaOrg\Schema;

$localBusiness = Schema::localBusiness()
    ->name('Spatie')
    ->email('info@spatie.be')
    ->contactPoint(Schema::contactPoint()->areaServed('Worldwide'));

echo $localBusiness->toScript();
```

```

{
    "@context": "https:\/\/schema.org",
    "@type": "LocalBusiness",
    "name": "Spatie",
    "email": "info@spatie.be",
    "contactPoint": {
        "@type": "ContactPoint",
        "areaServed": "Worldwide"
    }
}

```

Support us
----------

[](#support-us)

[![](https://camo.githubusercontent.com/8a79de9f2020de38f6d3d6b854dee32e3b0ef23c342aadd2e2af91c9ff3b1ce2/68747470733a2f2f6769746875622d6164732e73332e65752d63656e7472616c2d312e616d617a6f6e6177732e636f6d2f736368656d612d6f72672e6a70673f743d31)](https://spatie.be/github-ad-click/schema-org)

We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require spatie/schema-org
```

Usage
-----

[](#usage)

All types can be instantiated through the `Spatie\SchemaOrg\Schema` factory class, or with the `new` keyword.

```
$localBusiness = Schema::localBusiness()->name('Spatie');

// Is equivalent to:

$localBusiness = new LocalBusiness();
$localBusiness->name('Spatie');
```

> *All types also accept arrays of the expected data type, for example `sameAs` accepts a string or an array of strings.*

All types also implement the SPL's `ArrayAccess` for accessing the properties via array notation:

```
$anotherLocalBusiness = new LocalBusiness();
var_dump(isset($anotherLocalBusiness['name'])); // => false
$anotherLocalBusiness['name'] = 'Spatie';
var_dump(isset($anotherLocalBusiness['name'])); // => true
var_dump($anotherLocalBusiness['name']); // => 'Spatie'
unset($anotherLocalBusiness['name']);
var_dump(isset($anotherLocalBusiness['name'])); // => false
```

Types can be converted to an array or rendered to a script.

```
$localBusiness->toArray();

echo $localBusiness->toScript();

echo $localBusiness; // Same output as `toScript()`
```

Additionally, all types can be converted to a plain JSON string by just calling `json_encode()` with your object:

```
echo json_encode($localBusiness);
```

I recommend double checking your structured data with [Google's structured data testing tool](https://search.google.com/structured-data/testing-tool).

### Enumerations

[](#enumerations)

As of v1.6.0, all [Enumeration](https://schema.org/Enumeration) child types are available as classes with constants.

```
Schema::book()->bookFormat(Spatie\SchemaOrg\BookFormatType::Hardcover);
```

There's no full API documentation for types and properties. You can refer to [the source](https://github.com/spatie/schema-org/tree/master/src) or to [the schema.org website](https://schema.org).

If you don't want to break the chain of a large schema object, you can use the `if` method to conditionally modify the schema.

```
use Spatie\SchemaOrg\LocalBusiness;
use Spatie\SchemaOrg\Schema;

$business = ['name' => 'Spatie'];

$localBusiness = Schema::localBusiness()
    ->name($business['name'])
    ->if(isset($business['email']), function (LocalBusiness $schema) use ($business) {
        $schema->email($business['email']);
    });
```

### Identifier

[](#identifier)

As of v2.6.0 the `identifier` key is replaced by `@id` for simple string identifiers. This is due to the definition for the `ld+json` syntax.

> All schema.org syntaxes already have built-in representation for URIs and URLs, e.g. in Microdata 'itemid', in RDFa 1.1, 'resource', **in JSON-LD, '@id'.**
>
> — [schema.org/docs](https://schema.org/docs/datamodel.html#identifierBg) // [PR#102](https://github.com/spatie/schema-org/pull/102) // [PR#157](https://github.com/spatie/schema-org/pull/157)

### Advanced Usage

[](#advanced-usage)

If you'd need to set a custom property, you can use the `setProperty` method.

```
$localBusiness->setProperty('foo', 'bar');
```

If you'd need to retrieve a property, you can use the `getProperty` method. You can optionally pass in a second parameter to provide a default value.

```
$localBusiness->getProperty('name'); // 'Spatie'
$localBusiness->getProperty('bar'); // null
$localBusiness->getProperty('bar', 'baz'); // 'baz'
```

All properties can be retrieved as an array with the `getProperties` method.

```
$localBusiness->getProperties(); // ['name' => 'Spatie', ...]
```

Multiple properties can be set at once using the `addProperties` method.

```
$localBusiness->addProperties(['name' => 'value', 'foo' => 'bar']);
```

Context and type can be retrieved with the `getContext` and `getType` methods.

```
$localBusiness->getContext(); // 'https://schema.org'
$localBusiness->getType(); // 'LocalBusiness'
```

### Graph - multiple items

[](#graph---multiple-items)

The Graph has a lot of methods and utilities - the type-safe and simplest way is to use the overloaded methods of the `Spatie\SchemaOrg\Schema` class itself. These methods will get an already created or new instance of the requested schema.

```
$graph = new Graph();

// Create a product and prelink organization
$graph
    ->product()
    ->name('My cool Product')
    ->brand($graph->organization());

// Hide the organization from the created script tag
$graph->hide(\Spatie\SchemaOrg\Organization::class);

// Somewhere else fill out the organization
$graph
    ->organization()
    ->name('My awesome Company');

// Render graph to script tag
echo $graph;
```

With these tools the graph is a collection of all available schemas, can link these schemas with each other and prevent helper schemas from being rendered in the script-tag.

### Graph Node identifiers

[](#graph-node-identifiers)

Sometimes you have to keep track of multiple Graph nodes of the same type - for example multiple `Person` nodes for different people in your Organization. To do so you are able to use node identifiers on your graph instance. If you don't provide an identifier a reserved keyword `default` identifier will be used.

```
use Spatie\SchemaOrg\Graph;
use Spatie\SchemaOrg\Person;

$graph = new Graph();

// add a Person using chaining
$graph->person('freekmurze')
    ->givenName('Freek')
    ->familyName('Van der Herten')
    ->alternateName('freekmurze');

// add a Person using closure
$graph->person('sebastiandedeyne', function(Person $sebastian, Graph $graph): void {
    $sebastian
        ->givenName('Sebastian')
        ->familyName('De Deyne')
        ->alternateName('sebastiandedeyne');
});

// add a person using closure and second call with same identifier
$graph->person(
    'gummibeer',
    fn(Person $gummibeer) => $gummibeer->alternateName('gummibeer')
);
$graph->person('gummibeer')
    ->givenName('Tom')
    ->familyName('Witkowski');

$graph->person('random')->name('Random Person');

// hide the random person from Graph
$graph->hide(Person::class, 'random');

echo json_encode($graph);
```

```
{
    "@context":"https:\/\/schema.org",
    "@graph":[
        {
            "@type":"Person",
            "givenName":"Freek",
            "familyName":"Van der Herten",
            "alternateName":"freekmurze"
        },
        {
            "@type":"Person",
            "givenName":"Sebastian",
            "familyName":"De Deyne",
            "alternateName":"sebastiandedeyne"
        },
        {
            "@type":"Person",
            "alternateName":"gummibeer",
            "givenName":"Tom",
            "familyName":"Witkowski"
        }
    ]
}
```

### Multi Typed Entities

[](#multi-typed-entities)

Schema.org allows [multi typed entities](https://github.com/schemaorg/schemaorg/wiki/How-to-use-Multi-Typed-Entities-or-MTEs) - to use them with this package you can use the `MultiTypedEntity` class - which works similar to the graph.

```
$mte = new MultiTypedEntity();
$mte->hotelRoom()->name('The Presidential Suite');
$mte->product()->offers(
    Schema::offer()
        ->name('One Night')
        ->price(100000.00)
        ->priceCurrency('USD')
);
$mte->product(function (Product $product) {
    $product->aggregateRating(
        Schema::aggregateRating()
            ->bestRating(5)
            ->worstRating(4)
    );
});

echo json_encode($mte);
```

```
{
   "@context":"https:\/\/schema.org",
   "@type":[
      "HotelRoom",
      "Product"
   ],
   "name":"The Presidential Suite",
   "offers":{
      "@type":"Offer",
      "name":"One Night",
      "price":100000,
      "priceCurrency":"USD"
   },
   "aggregateRating":{
      "@type":"AggregateRating",
      "bestRating":5,
      "worstRating":4
   }
}
```

There isn't a real rule in place how the properties are merged. It only uses `array_merge()` behind the scenes. So you should avoid defining the same property on different types in the MTE or be sure that all properties hold the same value that it's not important which property is used at the end.

Known Issues
------------

[](#known-issues)

- The `Float` type isn't available since it's a reserved keyword in PHP
- The `Physician` type isn't available since it extends a type from the `health` extension spec

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Testing
-------

[](#testing)

```
$ composer test
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you've found a bug regarding security please mail  instead of using the issue tracker.

Postcardware
------------

[](#postcardware)

You're free to use this package, but if it makes it to your production environment we highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using.

Our address is: Spatie, Kruikstraat 22, 2018 Antwerp, Belgium.

We publish all received postcards [on our company website](https://spatie.be/en/opensource/postcards).

Credits
-------

[](#credits)

- [Sebastian De Deyne](https://github.com/sebastiandedeyne)
- [Tom Witkowski](https://github.com/Gummibeer)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

33

—

LowBetter than 74% of packages

Maintenance48

Moderate activity, may be stable

Popularity14

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

5

Last Release

414d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/f46fe64973c3e89d15c745c0bf601c25983bafea81d30e64d4bf813a6f8c8c7c?d=identicon)[sebastianthulin](/maintainers/sebastianthulin)

---

Top Contributors

[![Gummibeer](https://avatars.githubusercontent.com/u/6187884?v=4)](https://github.com/Gummibeer "Gummibeer (235 commits)")[![sebastiandedeyne](https://avatars.githubusercontent.com/u/1561079?v=4)](https://github.com/sebastiandedeyne "sebastiandedeyne (93 commits)")[![mallardduck](https://avatars.githubusercontent.com/u/619938?v=4)](https://github.com/mallardduck "mallardduck (49 commits)")[![freekmurze](https://avatars.githubusercontent.com/u/483853?v=4)](https://github.com/freekmurze "freekmurze (43 commits)")[![AdrianMrn](https://avatars.githubusercontent.com/u/12762044?v=4)](https://github.com/AdrianMrn "AdrianMrn (8 commits)")[![Nielsvanpach](https://avatars.githubusercontent.com/u/10651054?v=4)](https://github.com/Nielsvanpach "Nielsvanpach (7 commits)")[![ThomasRedstone](https://avatars.githubusercontent.com/u/3607652?v=4)](https://github.com/ThomasRedstone "ThomasRedstone (6 commits)")[![thorbrink](https://avatars.githubusercontent.com/u/1064724?v=4)](https://github.com/thorbrink "thorbrink (6 commits)")[![neildaniels](https://avatars.githubusercontent.com/u/417182?v=4)](https://github.com/neildaniels "neildaniels (5 commits)")[![otsch](https://avatars.githubusercontent.com/u/4062813?v=4)](https://github.com/otsch "otsch (5 commits)")[![patrickomeara](https://avatars.githubusercontent.com/u/571773?v=4)](https://github.com/patrickomeara "patrickomeara (4 commits)")[![jose-gomez-evinex](https://avatars.githubusercontent.com/u/65082532?v=4)](https://github.com/jose-gomez-evinex "jose-gomez-evinex (3 commits)")[![Toflar](https://avatars.githubusercontent.com/u/481937?v=4)](https://github.com/Toflar "Toflar (2 commits)")[![alexbowers](https://avatars.githubusercontent.com/u/842974?v=4)](https://github.com/alexbowers "alexbowers (2 commits)")[![AlexVanderbist](https://avatars.githubusercontent.com/u/6287961?v=4)](https://github.com/AlexVanderbist "AlexVanderbist (2 commits)")[![dougblackjr](https://avatars.githubusercontent.com/u/6020323?v=4)](https://github.com/dougblackjr "dougblackjr (2 commits)")[![graste](https://avatars.githubusercontent.com/u/203540?v=4)](https://github.com/graste "graste (2 commits)")[![pascalmoser](https://avatars.githubusercontent.com/u/7426193?v=4)](https://github.com/pascalmoser "pascalmoser (2 commits)")[![patinthehat](https://avatars.githubusercontent.com/u/5508707?v=4)](https://github.com/patinthehat "patinthehat (2 commits)")[![Soean](https://avatars.githubusercontent.com/u/695201?v=4)](https://github.com/Soean "Soean (2 commits)")

---

Tags

schema-orghelsingborg

###  Code Quality

TestsPest

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/helsingborg-stad-schema-org/health.svg)

```
[![Health](https://phpackages.com/badges/helsingborg-stad-schema-org/health.svg)](https://phpackages.com/packages/helsingborg-stad-schema-org)
```

###  Alternatives

[spatie/schema-org

A fluent builder Schema.org types and ld+json generator

1.5k10.4M78](/packages/spatie-schema-org)[simialbi/yii2-schema-org

Schema.org yii2 representation and helpers for json-ld generation in Yii framework

18102.7k4](/packages/simialbi-yii2-schema-org)[larament/seokit

A complete SEO package for Laravel, covering everything from meta tags to social sharing and structured data.

411.9k](/packages/larament-seokit)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
