Home >PHP Framework >Laravel >Teach you how to use laravel-like-comment comment plug-in
The following tutorial column will introduce you to the use of laravel-like-comment comment plug-in, I hope it will be helpful to friends in need!
Laravel like comment
Function
composer require risul/laravel-like-comment
risul\LaravelLikeComment\LikeCommentServiceProvider::classto your service providerr
php artisan vendor:publish
Migrate the data table Create data tables related to comments.
php artisan migrateAdd comment css style in the head of the page you need to comment on.
<link href="//cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.2.2/components/icon.min.css" rel="stylesheet"> <link href="//cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.2.2/components/comment.min.css" rel="stylesheet"> <link href="//cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.2.2/components/form.min.css" rel="stylesheet"> <link href="//cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.2.2/components/button.min.css" rel="stylesheet"> <link href="{{ asset('/vendor/laravelLikeComment/css/style.css') }}" rel="stylesheet">Add jquery and script
Note : Because jquery in the original article uses Google resources, I modified it to domestic.
<script src="https://cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js"></script> <script src="{{ asset('/vendor/laravelLikeComment/js/script.js') }}" type="text/javascript"></script>Add the user model path in
config/laravelLikeComment.php
Note: Be optimistic about your user model path and whether to modify it. The default path is below.
'userModel' => 'App\User'Add the following code to your user model.
Use on the page you want to add likes to Add the following code./** * Return the user attributes. * @return array */ public static function getAuthor($id) { $user = self::find($id); return [ 'id' => $user->id, 'name' => $user->name, 'email' => $user->email, 'url' => '', // Optional 'avatar' => 'gravatar', // Default avatar 'admin' => $user->role === 'admin', // bool ]; }
@include('laravelLikeComment::like', ['like_item_id' => 'image_31'])like_item_id:
For example, I want to display the article in the article post model Add this function to the page and mark it in the data table. The detailed information of this data can be combined and marked post_1 (post is the article model, 1 is the article id). The quote is as follows:
@include('laravelLikeComment::like', ['like_item_id' => "post_".$post->id])
Add the following code in the module where you want to add comments:The marking method is as above
@include('laravelLikeComment::comment', ['comment_item_id' => 'video_12'])
comment_item_id:is the comment tag id of the module to be integrated.
The above is the detailed content of Teach you how to use laravel-like-comment comment plug-in. For more information, please follow other related articles on the PHP Chinese website!