user(); assert($viewer !== null); Gate::forUser($viewer)->authorize('moderate', FileComment::class); $pending = FileComment::query() ->whereNull('approved_at') ->whereIn('file_id', $this->library->files($viewer)->select('id')) ->with(['author', 'clientContext']) ->orderBy('created_at') ->orderBy('id') ->get(); return FileCommentResource::collection($pending); } /** * Approve a comment left by a visitor. * * Nobody can see it until this happens. Approving an already-approved * comment changes nothing and announces nothing, so a retried request * is safe — which matters more here than on the web, where a human does * not retry automatically. */ public function approve(Request $request, FileComment $comment): FileCommentResource { $viewer = $request->user(); assert($viewer !== null); // Moderation rights are not a way around the library boundary; the // policy weighs the comment's file, so name the comment. Gate::authorize('moderate', $comment); $this->comments->approve($comment, $viewer); return new FileCommentResource($comment->fresh()?->load(['author', 'clientContext']) ?? $comment); } }