From b27ddbbe7d9e01246a72826e60c1d5554af7923a Mon Sep 17 00:00:00 2001 From: fthvgb1 Date: Sun, 10 Jun 2018 22:40:18 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=9E=E5=A4=8D=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Models/Reply.php | 1 + app/Transformers/ReplyTransformer.php | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/Models/Reply.php b/app/Models/Reply.php index 5f5fbb0..7841842 100644 --- a/app/Models/Reply.php +++ b/app/Models/Reply.php @@ -11,6 +11,7 @@ namespace App\Models; * @property int user_id * @property int topic_id * @property User user + * @property Topic topic * @package App\Models */ class Reply extends Model diff --git a/app/Transformers/ReplyTransformer.php b/app/Transformers/ReplyTransformer.php index 51a0cf3..f614c8a 100644 --- a/app/Transformers/ReplyTransformer.php +++ b/app/Transformers/ReplyTransformer.php @@ -15,7 +15,7 @@ use League\Fractal\TransformerAbstract; class ReplyTransformer extends TransformerAbstract { - protected $availableIncludes = ['user']; + protected $availableIncludes = ['user', 'topic']; public function transform(Reply $reply) { @@ -29,6 +29,11 @@ class ReplyTransformer extends TransformerAbstract ]; } + public function includeTopic(Reply $reply) + { + return $this->item($reply->topic, new TopicTransformer()); + } + public function includeUser(Reply $reply) { return $this->item($reply->user, new UserTransformer());