App\Http\Controllers\CommentsController::recursiveDestroy PHP Method

recursiveDestroy() public method

Delete comment recursively
public recursiveDestroy ( App\Comment $comment ) : boolean | null
$comment App\Comment
return boolean | null
    public function recursiveDestroy(Comment $comment)
    {
        if ($comment->replies->count()) {
            $comment->replies->each(function ($reply) {
                if ($reply->replies->count()) {
                    $this->recursiveDestroy($reply);
                } else {
                    $reply->delete();
                }
            });
        }
        return $comment->delete();
    }