All Projects → beyondcode → Laravel Comments

beyondcode / Laravel Comments

Licence: mit
Add comments to your Laravel application

Projects that are alternatives of or similar to Laravel Comments

Comments
Native comments for your Laravel application.
Stars: ✭ 390 (+66.67%)
Mutual labels:  comments, laravel
Laravel Disqus
A simple Disqus platform integration with Laravel.
Stars: ✭ 71 (-69.66%)
Mutual labels:  comments, laravel
Laravel Commentable
Stars: ✭ 141 (-39.74%)
Mutual labels:  comments, laravel
Laravel React Blog
基于 Laravel 5.5 和 React 的个人博客系统
Stars: ✭ 226 (-3.42%)
Mutual labels:  laravel
Laravel Crawler Detect
A Laravel wrapper for CrawlerDetect - the web crawler detection library
Stars: ✭ 227 (-2.99%)
Mutual labels:  laravel
Laravel Auth
Laravel 8 with user authentication, registration with email confirmation, social media authentication, password recovery, and captcha protection. Uses offical [Bootstrap 4](http://getbootstrap.com). This also makes full use of Controllers for the routes, templates for the views, and makes use of middleware for routing. The project can be stood u…
Stars: ✭ 2,692 (+1050.43%)
Mutual labels:  laravel
Laravelcs
Laravel PHP_CodeSniffer
Stars: ✭ 232 (-0.85%)
Mutual labels:  laravel
Laravel Craftsman
Laravel Craftsman CLI for easily crafting Laravel assets for any project (artisan make on steroids)
Stars: ✭ 227 (-2.99%)
Mutual labels:  laravel
Laravel Cronless Schedule
Run the Laravel scheduler without relying on cron
Stars: ✭ 231 (-1.28%)
Mutual labels:  laravel
Tomatoidc
TomatoIDC是一款以MIT协议开源主机销售系统,具备易于扩展的插件系统,模版系统,使用强大的Laravel框架进行驱动,能帮助你轻松的扩展主机销售业务。
Stars: ✭ 230 (-1.71%)
Mutual labels:  laravel
Laravelmetatags
The most powerful and extendable tools for managing SEO Meta Tags in your Laravel project
Stars: ✭ 226 (-3.42%)
Mutual labels:  laravel
Laravel Database Mail Templates
Render Laravel mailables based on a mail template stored in the database
Stars: ✭ 226 (-3.42%)
Mutual labels:  laravel
Laravel Query Monitor
Simple artisan command to monitoring triggered queries
Stars: ✭ 230 (-1.71%)
Mutual labels:  laravel
Fata
From Apprentice To Artisan. 在线阅读
Stars: ✭ 227 (-2.99%)
Mutual labels:  laravel
Laravel Gentelella
A Laravel 5.4 application with Gentelella bootstrap admin tempalte
Stars: ✭ 232 (-0.85%)
Mutual labels:  laravel
Laravel Tag Helper
Add powerful HTML tag helpers to your Laravel application
Stars: ✭ 227 (-2.99%)
Mutual labels:  laravel
Laravel Docs
Laravel 中文文档
Stars: ✭ 231 (-1.28%)
Mutual labels:  laravel
Laravel Stock
Keep stock for Eloquent models
Stars: ✭ 229 (-2.14%)
Mutual labels:  laravel
Learn Laravel
Laravel 学习资料和开源项目集
Stars: ✭ 229 (-2.14%)
Mutual labels:  laravel
Tracker
Laravel Stats Tracker
Stars: ✭ 2,638 (+1027.35%)
Mutual labels:  laravel

Add comments to your Laravel application

Latest Version on Packagist Build Status Quality Score Total Downloads

Add the ability to associate comments to your Laravel Eloquent models. The comments can be approved and nested.

$post = Post::find(1);

$post->comment('This is a comment');

$post->commentAsUser($user, 'This is a comment from someone else');

Installation

You can install the package via composer:

composer require beyondcode/laravel-comments

The package will automatically register itself.

You can publish the migration with:

php artisan vendor:publish --provider="BeyondCode\Comments\CommentsServiceProvider" --tag="migrations"

After the migration has been published you can create the media-table by running the migrations:

php artisan migrate

You can publish the config-file with:

php artisan vendor:publish --provider="BeyondCode\Comments\CommentsServiceProvider" --tag="config"

Usage

Registering Models

To let your models be able to receive comments, add the HasComments trait to the model classes.

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use BeyondCode\Comments\Traits\HasComments;

class Post extends Model
{
    use HasComments;
    ...
}

Creating Comments

To create a comment on your commentable models, you can use the comment method. It receives the string of the comment that you want to store.

$post = Post::find(1);

$comment = $post->comment('This is a comment from a user.');

The comment method returns the newly created comment class.

Sometimes you also might want to create comments on behalf of other users. You can do this using the commentAsUser method and pass in your user model that should get associated with this comment:

$post = Post::find(1);

$comment = $post->commentAsUser($yourUser, 'This is a comment from someone else.');

Approving Comments

By default, all comments that you create are not approved - this is just a boolean flag called is_approved that you can use in your views/controllers to filter out comments that you might not yet want to display.

To approve a single comment, you may use the approve method on the Comment model like this:

$post = Post::find(1);
$comment = $post->comments->first();

$comment->approve();

Auto Approve Comments

If you want to automatically approve a comment for a specific user (and optionally model) you can let your User model implement the following interface and method:

namespace App\Models;

use BeyondCode\Comments\Contracts\Commentator;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable implements Commentator
{
    /**
     * Check if a comment for a specific model needs to be approved.
     * @param mixed $model
     * @return bool
     */
    public function needsCommentApproval($model): bool
    {
        return false;    
    }
    
}

The needsCommentApproval method received the model instance that you want to add a comment to and you can either return true to mark the comment as not approved, or return false to mark the comment as approved.

Retrieving Comments

The models that use the HasComments trait have access to it's comments using the comments relation:

$post = Post::find(1);

// Retrieve all comments
$comments = $post->comments;

// Retrieve only approved comments
$approved = $post->comments()->approved()->get();

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

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

Credits

License

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].