-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathPost.php
34 lines (31 loc) · 1.14 KB
/
Post.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php
namespace Modules\MyBlog\Http\Resources;
use App\Http\Resources\Setting\Category;
use Illuminate\Http\Resources\Json\JsonResource;
use Modules\MyBlog\Http\Resources\Comment;
class Post extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
*/
public function toArray($request)
{
return [
'id' => $this->id,
'company_id' => $this->company_id,
'name' => $this->name,
'description' => $this->description,
'category_id' => $this->category_id,
'enabled' => $this->enabled,
'created_by' => $this->created_by,
'created_from' => $this->created_from,
'created_at' => $this->created_at ? $this->created_at->toIso8601String() : '',
'updated_at' => $this->updated_at ? $this->updated_at->toIso8601String() : '',
'category' => new Category($this->category),
'comments' => [static::$wrap => Comment::collection($this->comments)],
];
}
}