-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Sameer Anand
authored
Apr 22, 2017
1 parent
46ebf1c
commit 59e0d36
Showing
1 changed file
with
18 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,15 +30,15 @@ This will create `app\Transformers\UserTransformer.php` | |
|
||
A generated transformer will look like this: | ||
```php | ||
class UserTransformer extends Transformer | ||
class UserTransformer extends Transformer | ||
{ | ||
public function transform($user) | ||
{ | ||
public function transform($user) | ||
{ | ||
return [ | ||
'name' => $user->first . ' ' . $user->last | ||
]; | ||
} | ||
return [ | ||
'name' => $user->first . ' ' . $user->last | ||
]; | ||
} | ||
} | ||
``` | ||
|
||
Modify the returned array in the transform method to define how you want the data to be transformed. | ||
|
@@ -48,23 +48,23 @@ Modify the returned array in the transform method to define how you want the dat | |
You can transform a single item using the transform method. For example: | ||
|
||
```php | ||
public function show(User $user, UserTransformer $transformer) | ||
{ | ||
return $transformer->transform($user); | ||
} | ||
public function show(User $user, UserTransformer $transformer) | ||
{ | ||
return $transformer->transform($user); | ||
} | ||
``` | ||
|
||
You can transform a collection of items using the transformCollection method. For example: | ||
|
||
```php | ||
public function index(UserTransformer $transformer) | ||
{ | ||
$users = User::all(); | ||
$transformer->transformCollection($users); | ||
} | ||
public function index(UserTransformer $transformer) | ||
{ | ||
$users = User::all(); | ||
|
||
$transformer->transformCollection($users); | ||
} | ||
``` | ||
|
||
## License | ||
|
||
Released under the MIT License, Copyright (c) 2017 - Sameer Anand (<[email protected]>) | ||
Released under the MIT License, Copyright (c) 2017 - Sameer Anand (<[email protected]>) |