1. Go to this page and download the library: Download imagina/ihelpers-module 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/ */
' 'EntityTransformer'=>[
'otherEntity'=>[
'path'=>'Modules\Iothermodule\Transformers\OtherEntityTransformer', //this is the transformer path
'multiple'=>false, //if the relationship is one-to-many, multiple must be set to true
],
],
...
],
'relations' =>[
'entity'=>[
'otherEntity' => function () {
return $this->hasOne(
\Modules\Iothermodule\Entities\OtherEntity::class, 'model_id');
},
],
...
],
use Modules\Ihelpers\Traits\Relationable;
class Entity extends Model{
use Relationable;
use Modules\Ihelpers\Traits\Transformeable;
class EntityTransformer extends JsonResource{
use Transformeable;