在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):laravelista/comments开源软件地址(OpenSource Url):https://github.com/laravelista/comments开源编程语言(OpenSource Language):PHP 64.5%开源软件介绍(OpenSource Introduction):CommentsComments is a Laravel package. With it you can easily implement native comments for your application. OverviewThis package can be used to comment on any model you have in your application. All comments are stored in a single table with a polymorphic relation for content and a polymorphic relation for the user who posted the comment. Features
ScreenshotsHere are a few screenshots. No comments & guest: No comments & logged in: One comment: One comment edit form: Two comments from different users: Tutorials & articlesI plan to expand this chapter with more tutorials and articles. If you write something about this package let me know, so that I can update this chapter. Screencasts:
InstallationFrom the command line: composer require laravelista/comments Run migrationsWe need to create the table for comments. php artisan migrate Add Commenter trait to your User modelAdd the use Laravelista\Comments\Commenter;
class User extends Authenticatable
{
use Notifiable, Commenter;
} Add Commentable trait to modelsAdd the use Laravelista\Comments\Commentable;
class Product extends Model
{
use Commentable;
} Publish Config & configure (optional)Publish the config file (optional): php artisan vendor:publish --provider="Laravelista\Comments\ServiceProvider" --tag=config Publish views (customization)The default UI is made for Bootstrap 4, but you can change it however you want. php artisan vendor:publish --provider="Laravelista\Comments\ServiceProvider" --tag=views Publish Migrations (customization)You can publish migration to allow you to have more control over your table php artisan vendor:publish --provider="Laravelista\Comments\ServiceProvider" --tag=migrations Publish translations (customization)The package currently only supports English, but I am open to PRs for other languages. php artisan vendor:publish --provider="Laravelista\Comments\ServiceProvider" --tag=translations UsageIn the view where you want to display comments, place this code and modify it:
In the example above we are setting the If you open the page containing the view where you have placed the above code, you should see a working comments form. View only approved commentsTo view only approved comments, use this code:
Paginate commentsPagination paginates by top level comments only, meaning that if you specify the number of comments per page to be 1, and that one comment has 100 replies, it will display that one comment and all of its replies. It was not possible to do it any other way, because if I paginate by all comments (parent and child) you will end up with blank pages since the comments components loops parent comments first and then uses recursion for replies. To use pagination, use this code:
Replace Configure maximum indentation levelBy default the replies go up to level three. After that they are "mashed" at that level.
You can configure the maximum indentation level like so:
EventsThis package fires events to let you know when things happen.
REST APITo change the controller or the routes, see the config.
POST |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论