UserCollection.php 617 B

123456789101112131415161718192021222324252627
  1. <?php
  2. /*
  3. * This file is part of the Jiannei/lumen-api-starter.
  4. *
  5. * (c) Jiannei <longjian.huang@foxmail.com>
  6. *
  7. * This source file is subject to the MIT license that is bundled
  8. * with this source code in the file LICENSE.
  9. */
  10. namespace App\Http\Resources;
  11. use Illuminate\Http\Resources\Json\ResourceCollection;
  12. class UserCollection extends ResourceCollection
  13. {
  14. public function toArray($request)
  15. {
  16. return $this->collection->map(function ($item) {
  17. return [
  18. 'nickname' => $item->name,
  19. 'email' => $item->email,
  20. ];
  21. })->all();
  22. }
  23. }