PHPackages                             blackfyre/json-ld - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. blackfyre/json-ld

Abandoned → [blackfyre/json-ld](/?search=blackfyre%2Fjson-ld)ArchivedLibrary[Utility &amp; Helpers](/categories/utility)

blackfyre/json-ld
=================

Extremely simple JSON-LD markup generator.

0.0.11(7y ago)01.8k1BSD-2-ClausePHPPHP &gt;=5.5

Since Jan 8Pushed 7y ago1 watchersCompare

[ Source](https://github.com/blackfyre/json-ld)[ Packagist](https://packagist.org/packages/blackfyre/json-ld)[ RSS](/packages/blackfyre-json-ld/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)Dependencies (2)Versions (13)Used By (0)

JSON-LD Generator
=================

[](#json-ld-generator)

This a fork of [Torann's JSON-LD generator](https://github.com/Torann/json-ld), I've only extended it with missing things 😄

Extremely simple JSON-LD generator.

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

[](#installation)

- [JSON-LD Generator on Packagist](https://packagist.org/packages/blackfyre/json-ld)
- [JSON-LD Generator on GitHub](https://github.com/blackfyre/json-ld)

From the command line run

```
$ composer require blackfyre/json-ld

```

Methods
-------

[](#methods)

**/JsonLd/Context.php**

- `create($context, array $data = [])`
- `getProperties()`
- `generate()`

Context Types
-------------

[](#context-types)

- article
- beach
- blog\_posting
- breadcrumb\_list
- contact\_point
- corporation
- creative\_work
- duration
- event
- geo\_coordinates
- image\_object
- invoice
- job\_posting
- list\_item
- local\_business
- music\_album
- music\_group
- music\_playlist
- music\_recording
- news\_article
- offer
- order
- organization
- person
- place
- postal\_address
- price\_specification
- product
- rating
- review
- search\_box
- thing
- video\_object
- web\_page

Examples
--------

[](#examples)

### Quick Example

[](#quick-example)

#### Business

[](#business)

```
$context = \JsonLd\Context::create('local_business', [
    'name' => 'Consectetur Adipiscing',
    'description' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor',
    'telephone' => '555-555-5555',
    'openingHours' => 'mon,tue,fri',
    'address' => [
        'streetAddress' => '112 Apple St.',
        'addressLocality' => 'Hamden',
        'addressRegion' => 'CT',
        'postalCode' => '06514',
    ],
    'geo' => [
        'latitude' => '41.3958333',
        'longitude' => '-72.8972222',
    ],
]);

echo $context; // Will output the script tag
```

### News Article

[](#news-article)

```
$context = \JsonLd\Context::create('news_article', [
    'headline' => 'Article headline',
    'description' => 'A most wonderful article',
    'mainEntityOfPage' => [
        'url' => 'https://google.com/article',
    ],
    'image' => [
        'url' => 'https://google.com/thumbnail1.jpg',
        'height' => 800,
        'width' => 800,
    ],
    'datePublished' => '2015-02-05T08:00:00+08:00',
    'dateModified' => '2015-02-05T09:20:00+08:00',
    'author' => [
        'name' => 'John Doe',
    ],
    'publisher' => [
        'name' => 'Google',
        'logo' => [
          'url' => 'https://google.com/logo.jpg',
          'width' => 600,
          'height' => 60,
        ]
    ],
]);

echo $context; // Will output the script tag
```

### Using the JSON-LD in a Laracasts Presenter

[](#using-the-json-ld-in-a-laracasts-presenter)

Even though this example shows using the JSON-LD inside of a `Laracasts\Presenter` presenter, Laravel is not required for this package.

#### /App/Presenters/BusinessPresenter.php

[](#apppresentersbusinesspresenterphp)

```
