Skip to main content

Crate laravel_comments

Crate laravel_comments 

Source
Expand description

Comments for Laravel Rust models: threaded replies on laravel-nestedset, moderation, reactions, and events, read without N+1 queries.

Register the provider in src/app.rs, run laravel migrate, and declare the comment model with comment_model!:

use laravel::Application;

Application::configure().with_providers(|providers| {
    providers.add(laravel_comments::CommentsServiceProvider::new());
})

See the README for a walkthrough.

Modules§

abilities
The default answers to who may do what with a comment, for the application’s policy.
events
Events the package dispatches. Listen to them as to any Laravel Rust event; each one carries keys, so a listener loads what it needs.
markdown
Safe HTML from a comment’s Markdown, with the markdown feature.

Macros§

comment_model
Declares the application’s comment model and implements CommentModel for it.
comment_policy
Declares a policy with the package’s default abilities: update, delete, and reply on a comment, and moderate. Check them as any policy’s: user.authorize(CommentPolicy::update, &comment).await?.

Structs§

CommentColumns
The columns of a CommentModel.
CommentMention
A user mentioned in a comment, from the comment_mentions table.
CommentReaction
A user’s reaction to a comment, from the comment_reactions table.
CommentRevision
The text a comment had before an edit, from the comment_revisions table.
CommentRow
The values of a comment’s columns, as CommentModel::row reads them.
CommentsConfig
The package’s settings, read from the environment. An application changes them in with_config:
CommentsServiceProvider
Adds the package’s settings, its migrations, and the application’s moderation and mention rules.
Location
Where a comment shows on the pages of Threads, from Threads::locate.
NewComment
A comment about to be posted, as a moderation rule sees it.
ThreadNode
A comment in a thread, with its replies.
ThreadPage
A page of threads.
Threads
A query for threads, from CommentModel::threads or CommentModel::thread_tree.
UnknownAutoApprove
A COMMENTS_AUTO_APPROVE value other than everyone, users, or nobody.
UnknownBroadcastChannel
A COMMENTS_BROADCAST value other than off, public, or private.

Enums§

Author
The author of a new comment.
AutoApprove
Which new comments are approved at once. The rest wait for a moderator.
BroadcastChannel
How the events broadcast.
CommentError
An operation on a comment that can’t be done.
Sort
The order of top-level comments, and of the replies to each comment.
Status
Where a comment stands in moderation. Only approved comments are visible.
Visibility
How a comment shows in a thread.

Traits§

CommentModel
The application’s comment model.
Commenter
The application’s users model, as the author of comments.
CommentsBlueprint
Adds the columns of a comments table to a migration’s blueprint. The package’s own migration uses it for the comments table.

Functions§

mentions
The names mentioned in body, lowercased, each once, in order: @ followed by letters, digits, _, ., or -, up to 64 of them. An @ inside a word, as in an email address, and anything in `code` or a fenced code block don’t count, and a trailing . or - ends the sentence rather than the name.
reaction_counts
The number of each reaction on the comments with ids, in one query.
reactions_of
The reactions of the user with user_id on the comments with ids, in one query: what a page needs to show which reactions are the viewer’s.
throttle
Counts a comment by author against COMMENTS_RATE_LIMIT comments a minute: users by their key, guests by ip. Fails with TooManyAttempts, a 429 response with Retry-After, once the author posted too many.