Skip to content

Commit eba2ab3

Browse files
committed
Create UserGroupTransformer
1 parent d9c7087 commit eba2ab3

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php namespace Octobro\API\Transformers;
2+
3+
use RainLab\User\Models\UserGroup;
4+
use Octobro\API\Classes\Transformer;
5+
6+
class UserGroupTransformer extends Transformer
7+
{
8+
public function data(UserGroup $userGroup)
9+
{
10+
return [
11+
'id' => (int) $userGroup->id,
12+
'name' => $userGroup->name,
13+
'code' => $userGroup->code,
14+
'description' => $userGroup->description,
15+
];
16+
}
17+
}

transformers/UserTransformer.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55

66
class UserTransformer extends Transformer
77
{
8+
public $availableIncludes = [
9+
'groups',
10+
];
11+
812
public function data(User $user)
913
{
1014
return [
@@ -17,4 +21,9 @@ public function data(User $user)
1721
];
1822
}
1923

24+
public function includeGroups(User $user)
25+
{
26+
return $this->collection($user->groups, new UserGroupTransformer);
27+
}
28+
2029
}

0 commit comments

Comments
 (0)