MessageResource.php 870 B

1234567891011121314151617181920212223242526272829303132
  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\News;
  11. use Illuminate\Http\Resources\Json\JsonResource;
  12. class MessageResource extends JsonResource
  13. {
  14. public function toArray($request)
  15. {
  16. $model = $this;
  17. return [
  18. 'id' => (int)$model->id,
  19. 'message' => $model->message,
  20. 'type' => $model->type,
  21. 'resource' => $model->type == 2 ? $model->resource : null,
  22. 'resource_type' => $model->resource_type,
  23. 'resource_id' => $model->resource_id,
  24. 'is_read' => $model->is_read,
  25. 'created_at' => $model->created_at->format("Y-m-d H:i:s"),
  26. ];
  27. }
  28. }