I am using fractal
next to Laravel
to manipulate my collections
. In some Transformers I use available include
(as shown below).
What I would like to do is to include a goal with array
of those includes
.
Example:
meta:{includes: {include1: badah, include2: badah},data{dados...}
Code:
<?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());
}
}