From dc2a012e6e752fb588230357fe5cca08ad6889c4 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Wed, 2 Jan 2019 21:59:19 -0700 Subject: [PATCH] Update CommentController, prepare for Micro UI --- app/Http/Controllers/CommentController.php | 23 +++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/CommentController.php b/app/Http/Controllers/CommentController.php index 2c273527d..ab3953848 100644 --- a/app/Http/Controllers/CommentController.php +++ b/app/Http/Controllers/CommentController.php @@ -2,13 +2,18 @@ namespace App\Http\Controllers; +use Illuminate\Http\Request; +use Auth; + use App\Comment; use App\Jobs\CommentPipeline\CommentPipeline; use App\Jobs\StatusPipeline\NewStatusPipeline; use App\Profile; use App\Status; -use Auth; -use Illuminate\Http\Request; +use League\Fractal; +use App\Transformer\Api\StatusTransformer; +use League\Fractal\Serializer\ArraySerializer; +use League\Fractal\Pagination\IlluminatePaginatorAdapter; class CommentController extends Controller { @@ -57,7 +62,19 @@ class CommentController extends Controller CommentPipeline::dispatch($status, $reply); if ($request->ajax()) { - $response = ['code' => 200, 'msg' => 'Comment saved', 'username' => $profile->username, 'url' => $reply->url(), 'profile' => $profile->url(), 'comment' => $reply->caption]; + $fractal = new Fractal\Manager(); + $fractal->setSerializer(new ArraySerializer()); + $entity = new Fractal\Resource\Item($reply, new StatusTransformer()); + $entity = $fractal->createData($entity)->toArray(); + $response = [ + 'code' => 200, + 'msg' => 'Comment saved', + 'username' => $profile->username, + 'url' => $reply->url(), + 'profile' => $profile->url(), + 'comment' => $reply->caption, + 'entity' => $entity, + ]; } else { $response = redirect($status->url()); }