|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of laravel.su package. |
|
5
|
|
|
* |
|
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
7
|
|
|
* file that was distributed with this source code. |
|
8
|
|
|
*/ |
|
9
|
|
|
declare(strict_types=1); |
|
10
|
|
|
|
|
11
|
|
|
namespace App\GraphQL\Serializers; |
|
12
|
|
|
|
|
13
|
|
|
use App\Models\Article; |
|
14
|
|
|
use Illuminate\Database\Eloquent\Model; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Class ArticleSerializer. |
|
18
|
|
|
*/ |
|
19
|
|
|
class ArticleSerializer extends AbstractSerializer |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* @param Article|Model $article |
|
23
|
|
|
* @return array |
|
24
|
|
|
*/ |
|
25
|
|
|
public function toArray($article): array |
|
26
|
|
|
{ |
|
27
|
|
|
return [ |
|
28
|
|
|
'id' => $article->id, |
|
29
|
|
|
'title' => $article->capitalize_title, |
|
30
|
|
|
'slug' => $article->slug, |
|
31
|
|
|
'url' => route('articles.show', ['slug' => $article->slug]), |
|
32
|
|
|
'image' => $article->image_url, |
|
33
|
|
|
'content' => $article->content_rendered, |
|
34
|
|
|
'content_source' => $article->content_source, |
|
35
|
|
|
'preview' => $article->preview_rendered, |
|
36
|
|
|
'preview_source' => $article->preview_source, |
|
37
|
|
|
'status' => $article->status, |
|
38
|
|
|
'published_at' => $this->formatDateTime($article->published_at), |
|
39
|
|
|
'user' => UserSerializer::serialize($article->user), |
|
40
|
|
|
'tags' => TagSerializer::collection($article->tags), |
|
41
|
|
|
]; |
|
42
|
|
|
} |
|
43
|
|
|
} |
|
44
|
|
|
|