Skip to content

Commit 644b63a

Browse files
committed
feat(article): add all author related fields
1 parent e743a8b commit 644b63a

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

app/Http/Resources/Api/V1/Article/ArticleResource.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ public function toArray(Request $request): array
4343
'email' => $this->author->email,
4444
'avatar_url' => $this->author->avatar_url,
4545
'bio' => $this->author->bio,
46+
'twitter' => $this->author->twitter,
47+
'facebook' => $this->author->facebook,
48+
'linkedin' => $this->author->linkedin,
49+
'github' => $this->author->github,
50+
'website' => $this->author->website,
4651
] : null;
4752
}),
4853

@@ -86,6 +91,11 @@ public function toArray(Request $request): array
8691
'email' => $author->email,
8792
'avatar_url' => $author->avatar_url,
8893
'bio' => $author->bio,
94+
'twitter' => $author->twitter,
95+
'facebook' => $author->facebook,
96+
'linkedin' => $author->linkedin,
97+
'github' => $author->github,
98+
'website' => $author->website,
8999
'role' => $pivot?->getAttribute('role'),
90100
];
91101
})->values()->all();

app/Services/ArticleService.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class ArticleService
1919
public function getArticles(array $params): LengthAwarePaginator
2020
{
2121
$query = Article::query()
22-
->with(['author:id,name,email,avatar_url,bio', 'categories:id,name,slug', 'tags:id,name,slug'])
22+
->with(['author:id,name,email,avatar_url,bio,twitter,facebook,linkedin,github,website', 'categories:id,name,slug', 'tags:id,name,slug'])
2323
->withCount('comments');
2424

2525
// Apply filters
@@ -42,7 +42,7 @@ public function getArticleBySlug(string $slug): Article
4242
'author:id,name,email,avatar_url,bio,twitter,facebook,linkedin,github,website',
4343
'categories:id,name,slug',
4444
'tags:id,name,slug',
45-
'authors:id,name,email,avatar_url,bio',
45+
'authors:id,name,email,avatar_url,bio,twitter,facebook,linkedin,github,website',
4646
])
4747
->withCount('comments')
4848
->where('slug', $slug)

0 commit comments

Comments
 (0)