From 6fcbace0d8c6ffae00c2f75a0d7199fa9050482e Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sat, 13 Apr 2019 14:44:58 -0600 Subject: [PATCH] Update CommentController, increment reply count --- app/Http/Controllers/CommentController.php | 24 ++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/app/Http/Controllers/CommentController.php b/app/Http/Controllers/CommentController.php index 703241ce7..0a8e3b662 100644 --- a/app/Http/Controllers/CommentController.php +++ b/app/Http/Controllers/CommentController.php @@ -4,6 +4,7 @@ namespace App\Http\Controllers; use Illuminate\Http\Request; use Auth; +use DB; use Cache; use App\Comment; @@ -58,14 +59,21 @@ class CommentController extends Controller Cache::forget('transform:status:'.$status->url()); - $autolink = Autolink::create()->autolink($comment); - $reply = new Status(); - $reply->profile_id = $profile->id; - $reply->caption = e($comment); - $reply->rendered = $autolink; - $reply->in_reply_to_id = $status->id; - $reply->in_reply_to_profile_id = $status->profile_id; - $reply->save(); + $reply = DB::transaction(function() use($comment, $status, $profile) { + $autolink = Autolink::create()->autolink($comment); + $reply = new Status(); + $reply->profile_id = $profile->id; + $reply->caption = e($comment); + $reply->rendered = $autolink; + $reply->in_reply_to_id = $status->id; + $reply->in_reply_to_profile_id = $status->profile_id; + $reply->save(); + + $status->reply_count++; + $status->save(); + + return $reply; + }); NewStatusPipeline::dispatch($reply, false); CommentPipeline::dispatch($status, $reply);