PHP code example of kraenzle-ritter / entity-relations

1. Go to this page and download the library: Download kraenzle-ritter/entity-relations 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/ */

    

kraenzle-ritter / entity-relations example snippets


// config/entity-relations.php (published with --tag=entity-relations-config)
'entities' => [
    'keyword' => App\Models\Keyword::class,
    'actor' => App\Models\Actor::class,
    'place' => App\Models\Place::class,
],

$manager = app(KraenzleRitter\EntityRelations\RelationManager::class);

$manager->relate($nude, $painting, 'broader');            // stored as nude -> painting
$manager->relate($painting, $landscape, 'narrower');      // stored as landscape -> painting
$manager->relate($actor, $place, 'wasBornIn');
$manager->relate($a, $b, 'isSpouseOf', ['date_text' => '1901–1935']);

$manager->optionsFor($place, 'actor');   // ['isBirthPlaceOf' => 'Geburtsort von', ...]
$manager->relationsOf($painting);        // RelationView: name, label, other entity

$broader = $manager->types()->get('broader');
$manager->hierarchy()->descendantIds('keyword', $painting->id, $broader);
$manager->hierarchy()->primaryPath('keyword', $nude->id, $broader);