Estou utilizando o fractal
junto ao Laravel
para manipular minhas collections
. Em alguns Transformers utilizo o available include
(conforme exemplo abaixo).
O que eu gostaria de fazer é incluir um meta com array
desses includes
.
Exemplo:
meta:{includes: {include1: badah, include2: badah},data{dados...}
Código:
<?php
namespace apiAneel\Transformers;
use apiAneel\Entities\AccountPlan;
use League\Fractal\TransformerAbstract;
/**
* Class AccountPlanTransformer
* @package namespace apiAneel\Transformers;
*/
class AccountPlanTransformer extends TransformerAbstract
{
public $availableIncludes = ['acrCod', 'companyType'];
/**
* Transform the \AccountPlan entity
* @param \AccountPlan $model
*
* @return array
*/
public function transform(AccountPlan $model)
{
return [
'id' => $model->id,
'cod' => $model->cod,
'description' => $model->description,
'dep_cod' => $model->dep_cod,
'dep_description' => $model->dep_description,
'expense_cod' => $model->expense_cod,
'expense_description' => $model->expense_description
];
}
public function includeAcrCod(AccountPlan $accountPlan)
{
$acrCod = $accountPlan->acrCod;
return $this->item($acrCod, new AcrCodTransformer());
}
public function includeCompanyType(AccountPlan $accountPlan)
{
$companyType = $accountPlan->companyType;
return $this->item($companyType, new CompanyTypeTransformer());
}
}