2015-11-03 15:21:17 +01:00
|
|
|
<?php namespace App\Ninja\Transformers;
|
|
|
|
|
|
|
|
use App\Models\User;
|
|
|
|
use League\Fractal;
|
|
|
|
use League\Fractal\TransformerAbstract;
|
2015-11-05 09:44:48 +01:00
|
|
|
use League\Fractal\Resource\Item;
|
2015-11-03 15:21:17 +01:00
|
|
|
|
|
|
|
class UserAccountTransformer extends TransformerAbstract
|
|
|
|
{
|
2015-11-05 09:44:48 +01:00
|
|
|
protected $defaultIncludes = [
|
|
|
|
'user'
|
|
|
|
];
|
2015-11-03 15:21:17 +01:00
|
|
|
|
2015-11-05 09:44:48 +01:00
|
|
|
protected $tokenName;
|
|
|
|
|
2015-11-04 16:23:22 +01:00
|
|
|
public function __construct($tokenName)
|
2015-11-03 15:21:17 +01:00
|
|
|
{
|
2015-11-04 16:23:22 +01:00
|
|
|
$this->tokenName = $tokenName;
|
2015-11-03 15:21:17 +01:00
|
|
|
}
|
|
|
|
|
2015-11-05 09:44:48 +01:00
|
|
|
public function includeUser(User $user)
|
|
|
|
{
|
|
|
|
return $this->item($user, new UserTransformer);
|
|
|
|
}
|
|
|
|
|
2015-11-03 15:21:17 +01:00
|
|
|
public function transform(User $user)
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'account_key' => $user->account->account_key,
|
2015-11-06 11:59:53 +01:00
|
|
|
'name' => $user->account->present()->name,
|
2015-11-04 16:23:22 +01:00
|
|
|
'token' => $user->account->getToken($this->tokenName),
|
2015-11-03 15:21:17 +01:00
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|