2017 © Pedro Peláez
 

library laravel-comment

Comments for Laravel 5.4 and up

image

finagin/laravel-comment

Comments for Laravel 5.4 and up

  • Thursday, June 29, 2017
  • by finagin
  • Repository
  • 1 Watchers
  • 0 Stars
  • 12 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

Comments for Laravel 5.4 and up

Latest Version on Packagist ![Software License][ico-license] Build Status StyleCI ![Total Downloads][ico-downloads], (*1)

![GitHub stars][ico-github], (*2)

Installation

This package can be used in Laravel 5.4 or higher. You can install the package via composer:, (*3)

composer require finagin/laravel-comment

Now add the service provider in config/app.php file:, (*4)

'providers' => [
    /*
     * Package Service Providers...
     */
    // ...
    Finagin\Comment\CommentServiceProvider::class,
    // ...
];

You must publish the migration with:, (*5)

php artisan vendor:publish --provider="Finagin\Comment\CommentServiceProvider" --tag="migrations"

After the migration has been published you must create the settings-tables by running the migrations:, (*6)

php artisan migrate

Also you can publish the config file with:, (*7)

php artisan vendor:publish --provider="Finagin\Comment\CommentServiceProvider" --tag="config"

Add CanComment trait to your User model. ``` php use Finagin\Comment\Traits\CanComment;, (*8)


Add `Commentable` trait to your commentable model(s). ``` php use Finagin\Comment\Traits\Commentable;

If you want to have your own Comment Model create a new one and extend my Comment model. ``` php class Comment extends Finagin\Comment\Models\Comment { ... }, (*9)


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. ``` php class Post 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. ``` php class Post extends Model { use Commentable;, (*10)

protected $mustBeApproved = true;, (*11)

... }, (*12)


## Usage ``` php $user = App\User::find(1); $post = App\Post::find(1); // CanComment->comment(Commentable|Commnet $commentable, string $commentText): Comment // Anonimous first level comment $comment = (new User(['name' => 'Anonymous']))->comment($post, 'Lorem ipsum ..'); // Users sub comment $user ->comment($comment, 'Lorem ipsum ..'); // Anonimous sub comment (new User(['name' => 'Anonymous'])) ->comment($comment, 'Lorem ipsum ..');

License

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

The Versions