1. Go to this page and download the library: Download hungcrush/schema-org library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
$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;
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);