ArticleResource.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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\CMS;
  11. use Illuminate\Http\Resources\Json\JsonResource;
  12. class ArticleResource extends JsonResource
  13. {
  14. public function toArray($request)
  15. {
  16. $model = $this;
  17. return [
  18. 'id' => (int)$model->id,
  19. 'title' => $model->title,
  20. 'category_id' => $model->category_id,
  21. 'category_name' => $model->category ? $model->category->name : '--',
  22. 'cover_resource' => $model->cover_resource,
  23. 'short_description' => $model->short_description,
  24. 'tags' => $model->tags,
  25. 'slug' => $model->slug,
  26. 'body' => $model->body,
  27. 'organization_id' => $model->organization_id,
  28. 'organization' => $model->organization ? $model->organization : [],
  29. 'view_count' => $model->view_count,
  30. 'good_count' => $model->good_count,
  31. 'created_at' => $model->created_at->format("Y/m/d"),
  32. 'state' => $model->state,
  33. ];
  34. }
  35. }