Ajax based site wide like and comment system for laravel
risul/laravel-like-comment is a Laravel package for ajax based site wide like and comment system for laravel.
It currently has 108 GitHub stars and 7.393 downloads on Packagist (latest version v2.0.1).
Install it with composer require risul/laravel-like-comment.
Discover more Laravel packages by risul
or browse all Laravel packages to compare alternatives.
Last updated
Laravel Like Comment is a lightweight and developer-friendly package that makes it easy to add "like" and "comment" features to any Laravel model. Whether you're building a blog, forum, or social platform, this package handles the heavy lifting so you can focus on your core application.
It supports polymorphic relationships out of the box, allowing you to attach likes and comments to multiple models effortlessly. With clean API methods and customizable migrations, it's built to be both powerful and flexible.
Perfect for projects that need quick social interaction features without reinventing the wheel.
Run
composer require risul/laravel-like-comment
Add
risul\LaravelLikeComment\LikeCommentServiceProvider::class
in your service providerr list.
To copy views and migrations run
php artisan vendor:publish
Run
php artisan migrate
It will create like and comment table.
Add this style links to your view head
<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
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script src="{{ asset('/vendor/laravelLikeComment/js/script.js') }}" type="text/javascript"></script>
In config/laravelLikeComment.php add user model path
'userModel' => 'App\User'
Add following code in your user model
/**
* 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
];
}
Add this line at where you want to integrate Like
@include('laravelLikeComment::like', ['like_item_id' => 'image_31'])
like_item_id: This is the id of the item,page or model for which the like will be used
Add this line where you want to integrate Comment
@include('laravelLikeComment::comment', ['comment_item_id' => 'video_12'])
comment_item_id: This is the id of the item, page, or model for which the comment will be used