comments()->with('role', 'user')->orderByDesc('id'); $nopage = request()->input('nopage',0); if ($nopage) { $comments = $comments->get(); }else { $comments = $comments->paginate(); } foreach ($comments as $comment) { $comment->role_name = $comment->role? $comment->role->name:''; $comment->user_name = $comment->user? $comment->user->name:''; $comment->user_avatar = $comment->user? $comment->user->avatar:''; unset($comment->role, $comment->user); } return $comments; } public function commentOrder($order, $content, $user) { $order->commentAsUser($user, $content); return true; } }