Q:

How can I add an attribute to a database query before returning?

So I have something like this:
$comments = Comments::select('id', 'topic', 'parent_id', 'username', 'comment', 'upvotes', 'created_at', 'updated_at')
        ->where('topic', '=', $topic)
        ->get();

// I'd like to add a human readable datetime difference like
// 1 day ago, 2 days ago, etc. before I return the $comments variable here.

return json_encode($comments);

For a single row I would do something like this:
$comment->created_at->diffForHumans();

How can I add an extra attribute to all the rows, something like carbon_date?

A:

Loop through the $comments array and add the attribute to each element.
foreach ($comments as $comment) {
    $comment->carbon_date = $comment->created_at->diffForHumans();
}

