1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 23:22:52 +01:00
invoiceninja/app/Ninja/Transformers/UserAccountTransformer.php
2015-11-06 12:59:53 +02:00

34 lines
777 B
PHP

<?php namespace App\Ninja\Transformers;
use App\Models\User;
use League\Fractal;
use League\Fractal\TransformerAbstract;
use League\Fractal\Resource\Item;
class UserAccountTransformer extends TransformerAbstract
{
protected $defaultIncludes = [
'user'
];
protected $tokenName;
public function __construct($tokenName)
{
$this->tokenName = $tokenName;
}
public function includeUser(User $user)
{
return $this->item($user, new UserTransformer);
}
public function transform(User $user)
{
return [
'account_key' => $user->account->account_key,
'name' => $user->account->present()->name,
'token' => $user->account->getToken($this->tokenName),
];
}
}