1. Go to this page and download the library: Download norse-blue/parentity 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/ */
namespace App;
use App\Customers\Company;
use App\Customers\Person;
use Illuminate\Database\Eloquent\Model;
use NorseBlue\Parentity\Traits\IsMtiParentModel;
class Customer extends Model
{
use IsMtiParentModel;
protected $fillable = [
'name',
];
/** @optional */
protected $childTypeAliases = [
'person' => Person::class,
'company' => Company::class,
];
/** @optional */
protected $ownAttributes = [
'id',
'name',
'entity_type',
'entity_id',
];
}
namespace App;
use App\Customer;
use Illuminate\Database\Eloquent\Model;
use NorseBlue\Parentity\Traits\IsMtiChildModel;
class Person extends Model
{
use IsMtiChildModel;
protected $parentModel = Customer::class;
protected $parentEntity = 'entity';
protected $fillable = [
'last_name',
];
}
// using the previously created models
// Explicit property from the parent model
echo $customer->name . " " . $customer->entity->last_name;
// Explicit property from the child model
echo $person->parent->name . " " . $person->last_name;
// using the previously created models
// Implicit property from the parent model
echo $customer->name . " " . $customer->last_name;
// Implicit property from the child model
echo $person->name . " " . $person->last_name;
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.