Wallogit.com
2017 © Pedro Peláez
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., (*2)
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., (*3)
Perfect for projects that need quick social interaction features without reinventing the wheel., (*4)
Try it, (*5)
Watch, (*6)
Run, (*7)
composer require risul/laravel-like-comment
Add, (*8)
risul\LaravelLikeComment\LikeCommentServiceProvider::class
in your service providerr list., (*9)
To copy views and migrations run, (*10)
php artisan vendor:publish
Run, (*11)
php artisan migrate
It will create like and comment table., (*12)
Add this style links to your view head, (*13)
<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, (*14)
<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, (*15)
'userModel' => 'App\User'
Add following code in your user model, (*16)
/**
* 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, (*17)
@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, (*18)
Add this line where you want to integrate Comment, (*19)
@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, (*20)