actuallymab / laravel-comment
Just another comment system for your awesome Laravel project.
Installs: 164 035
Dependents: 4
Suggesters: 0
Security: 0
Stars: 234
Watchers: 12
Forks: 53
Open Issues: 11
Requires
- php: ^7.1.3
- illuminate/database: ~5.5.0|~5.6.0|~5.7.0|~5.8.0|^6.0|^7.0|^8.0
Requires (Dev)
- fzaninotto/faker: ^1.8
- orchestra/testbench: ~3.5.0|~3.6.0|~3.7.0|~3.8.0|^4.0|^5.0|^6.0
- phpunit/phpunit: ^7.4
- scrutinizer/ocular: ^1.5
README
Just another comment system for your awesome Laravel project.
Version Compatibility
Laravel | Laravel Comment |
---|---|
5.0.x | 0.1.x |
5.1.x | 0.1.x |
5.2.x | 0.1.x |
5.3.x | 0.2.x |
5.4.x | 0.3.x |
For >5.5
you can use ^1.0.0
version.
Install
Via Composer
$ composer require actuallymab/laravel-comment
If you don't use auto-discovery, or using Laravel version < 5.5 Add service provider to your app.php file
\Actuallymab\LaravelComment\LaravelCommentServiceProvider::class
Publish configurations and migrations, then migrate comments table.
$ php artisan vendor:publish $ php artisan migrate
Add CanComment
trait to your User model.
use Actuallymab\LaravelComment\CanComment; class User extends Model { use CanComment; // ... }
Add Commentable
interface and HasComments
trait to your commentable model(s).
use Actuallymab\LaravelComment\Contracts\Commentable; use Actuallymab\LaravelComment\HasComments; class Product extends Model implements Commentable { use HasComments; // ... }
If you want to have your own Comment Model create a new one and extend my Comment model.
use Actuallymab\LaravelComment\Models\Comment as LaravelComment; class Comment extends LaravelComment { // ... }
and dont forget to update the model name in the config/comment.php
file.
Comment package comes with several modes.
1- If you want to users can rate your commentable models;
class Product extends Model implements Commentable { use HasComments; public function canBeRated(): bool { return true; // default false } //... }
2- If you want to approve comments for your commentable models;
class Product extends Model implements Commentable { use HasComments; public function mustBeApproved(): bool { return true; // default false } // ... }
3- Sometimes you don't want to approve comments for all users;
class User extends Model { use CanComment; protected $fillable = [ 'isAdmin', // .. ]; public function canCommentWithoutApprove(): bool { return $this->isAdmin; } // .. }
Usage
$user = App\User::first(); $product = App\Product::first(); // $user->comment(Commentable $model, $comment = '', $rate = 0); $user->comment($product, 'Lorem ipsum ..', 3); // approve it -- if the user model `canCommentWithoutApprove()` or you don't use `mustBeApproved()`, it is not necessary $product->comments[0]->approve(); // get avg rating -- it calculates approved average rate. $product->averageRate(); // get total comments count -- it calculates approved comments count. $product->totalCommentsCount();
Tip: You might want to look at the tests/CommentTest.php file to check all potential usages.
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 mehmet.aydin.bahadir@gmail.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.