Giter Site home page Giter Site logo

glore / laravel-comment Goto Github PK

View Code? Open in Web Editor NEW

This project forked from actuallymab/laravel-comment

7.0 2.0 1.0 33 KB

Just another comment system for laravel projects.

Home Page: http://www.ufutx.com

License: MIT License

PHP 100.00%
ufutx comment

laravel-comment's Introduction

Laravel Comment (forked from actuallymab/laravel-comment)

Latest Version on Packagist Software License Build Status Total Downloads

**Just another comment system for laravel projects.

Version Compatibility

Laravel Laravel Comment
5.4.x 1.1.x
5.2.x 0.3.x

Install

Via Composer

$ composer require ufutx/laravel-comment

Add service provider to your app.php file

\Ufutx\LaravelComment\LaravelCommentServiceProvider::class

Publish & Migrate comments table.

$ php artisan vendor:publish
$ php artisan migrate

Add CanComment trait to your User model.

use Ufutx\LaravelComment\CanComment;

Add Commentable trait to your commentable model(s).

use Ufutx\LaravelComment\Commentable;

If you want to have your own Comment Model create a new one and extend my Comment model.

class Comment extends Ufutx\LaravelComment\Comment
{
  ...
}

Comment package comes with several modes.

1- If you want to Users can rate your model(s) with comment set canBeRated to true in your Commentable model.

class Product extends Model {
  use Commentable;

  protected $canBeRated = true;

  ...
}

2- If you want to approve comments for your commentable models, you must set mustBeApproved to true in your Commentable model.

class Product extends Model {
  use Commentable;

  protected $mustBeApproved = true;

  ...
}

3- You don't want to approve comments for all users (think this as you really want to approve your own comments?). So add your User model an isAdmin method and return it true if user is admin.

class User extends Model {
  use CanComment;
  
  protected $fillable = [
    'isAdmin',
    ....
  ];

  public function isAdmin() {
    return $this->isAdmin;
  }

  ...
}

Usage

$user = App\User::find(1);
$product = App\Product::find(1);

// $user->comment(Commentable $model, $comment = '', $rate = 0, $pic = null);
$user->comment($product, 'Lorem ipsum ..', 3, 'http://images.ufutx.com/201702/09/49fe31fdf2d4f74709f2cb00e1a9c49a.jpeg@1e_1c_2o_1l_200h_200w_90q.src');

// approve it -- if you are admin or you don't use mustBeApproved option, it is not necessary
$product->comments[0]->approve();

//comment user model record 
$product->comments[0]->user

// get avg rating -- it calculates approved average rate.
$product->averageRate();

// get total comment count -- it calculates approved comments count.
$product->totalCommentCount();

Change log

Please see CHANGELOG for more information what has changed recently.

Testing

$ composer test

Contributing

Please see CONTRIBUTING and CONDUCT for details.

Security

If you discover any security related issues, please email [email protected] or zglore instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

laravel-comment's People

Contributors

actuallymab avatar coding-sunshine avatar glore avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

hankin-h-k

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.