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
markdownfeature.
Macros§
- comment_
model - Declares the application’s comment model and implements
CommentModelfor it. - comment_
policy - Declares a policy with the package’s default abilities:
update,delete, andreplyon a comment, andmoderate. Check them as any policy’s:user.authorize(CommentPolicy::update, &comment).await?.
Structs§
- Comment
Columns - The columns of a
CommentModel. - Comment
Mention - A user mentioned in a comment, from the
comment_mentionstable. - Comment
Reaction - A user’s reaction to a comment, from the
comment_reactionstable. - Comment
Revision - The text a comment had before an edit, from the
comment_revisionstable. - Comment
Row - The values of a comment’s columns, as
CommentModel::rowreads them. - Comments
Config - The package’s settings, read from the environment. An application changes them in
with_config: - Comments
Service Provider - 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, fromThreads::locate. - NewComment
- A comment about to be posted, as a moderation rule sees it.
- Thread
Node - A comment in a thread, with its replies.
- Thread
Page - A page of threads.
- Threads
- A query for threads, from
CommentModel::threadsorCommentModel::thread_tree. - Unknown
Auto Approve - A
COMMENTS_AUTO_APPROVEvalue other thaneveryone,users, ornobody. - Unknown
Broadcast Channel - A
COMMENTS_BROADCASTvalue other thanoff,public, orprivate.
Enums§
- Author
- The author of a new comment.
- Auto
Approve - Which new comments are approved at once. The rest wait for a moderator.
- Broadcast
Channel - How the events broadcast.
- Comment
Error - 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§
- Comment
Model - The application’s comment model.
- Commenter
- The application’s users model, as the author of comments.
- Comments
Blueprint - Adds the columns of a comments table to a migration’s blueprint. The package’s own migration
uses it for the
commentstable.
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_idon the comments withids, in one query: what a page needs to show which reactions are the viewer’s. - throttle
- Counts a comment by
authoragainstCOMMENTS_RATE_LIMITcomments a minute: users by their key, guests byip. Fails withTooManyAttempts, a429response withRetry-After, once the author posted too many.