-
Notifications
You must be signed in to change notification settings - Fork 473
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(feed): ( issue #324 ) Add a get a single topic API
- Loading branch information
Showing
3 changed files
with
74 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* +----------------------------------------------------------------------+ | ||
* | ThinkSNS Plus | | ||
* +----------------------------------------------------------------------+ | ||
* | Copyright (c) 2018 Chengdu ZhiYiChuangXiang Technology Co., Ltd. | | ||
* +----------------------------------------------------------------------+ | ||
* | This source file is subject to version 2.0 of the Apache license, | | ||
* | that is bundled with this package in the file LICENSE, and is | | ||
* | available through the world-wide-web at the following url: | | ||
* | http://www.apache.org/licenses/LICENSE-2.0.html | | ||
* +----------------------------------------------------------------------+ | ||
* | Author: Slim Kit Group <master@zhiyicx.com> | | ||
* | Homepage: www.thinksns.com | | ||
* +----------------------------------------------------------------------+ | ||
*/ | ||
|
||
namespace Zhiyi\Plus\API2\Resources\Feed; | ||
|
||
use Illuminate\Http\Resources\Json\JsonResource; | ||
|
||
class Topic extends JsonResource | ||
{ | ||
/** | ||
* The topic resource to array. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @return array | ||
*/ | ||
public function toArray($request): array | ||
{ | ||
$user = $request->user('api'); | ||
|
||
return [ | ||
'id' => $this->id, | ||
'name' => $this->name, | ||
'logo' => $this->when($this->logo, $this->logo), | ||
'desc' => $this->when($this->desc, $this->desc), | ||
'creator_user_id' => $this->creator_user_id, | ||
'feeds_count' => $this->feeds_count, | ||
'followers_count' => $this->followers_count, | ||
'has_followed' => $this->when($user, function () use ($user) { | ||
return $this->followers()->where('user_id', $user->id)->exists(); | ||
}), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters