1. Go to this page and download the library: Download mll-lab/laravel-comment library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
mll-lab / laravel-comment example snippets
use Actuallymab\LaravelComment\CanComment;
final class User extends Model
{
use CanComment;
use Actuallymab\LaravelComment\Contracts\Commentable;
use Actuallymab\LaravelComment\HasComments;
final class Product extends Model implements Commentable
{
use HasComments;
use Actuallymab\LaravelComment\Models\Comment as LaravelComment;
final class Comment extends LaravelComment
final class Product extends Model implements Commentable
{
use HasComments;
public function canBeRated(): bool
{
return true; // default false
}
final class Product extends Model implements Commentable
{
use HasComments;
public function mustBeApproved(): bool
{
return true; // default false
}
final class User extends Model
{
use CanComment;
protected $fillable = [
'isAdmin',
];
public function canCommentWithoutApprove(): bool
{
return $this->isAdmin;
}
$user = User::firstOrFail();
$product = Product::firstOrFail();
// Pass the model to comment, the content and an optional rate
$user->comment($product, 'Lorem ipsum ..', 3);
// Only necessary if:
// - User::canCommentWithoutApprove() returns false
// - Product::mustBeApproved() returns true
$product->comments[0]->approve();
// Calculates the average rating of approved comments
$product->averageRate();
// Calculates the amount of approved comments
$product->totalCommentsCount();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.