Giter Site home page Giter Site logo

laravel-commentable's Introduction

Laravel Commentable

Build Status PHP from Packagist Latest Version License

Installation

Require this package, with Composer, in the root directory of your project.

$ composer require artisanry/commentable

To get started, you'll need to publish the vendor assets and migrate:

php artisan vendor:publish --provider="Artisanry\Commentable\CommentableServiceProvider" && php artisan migrate

Usage

Setup a Model

<?php

namespace App;


use Artisanry\Commentable\Traits\HasComments;
use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
    use HasComments;
}

Create a comment

$user = User::first();
$post = Post::first();

$comment = $post->comment([
    'title' => 'Some title',
    'body' => 'Some body',
], $user);

dd($comment);

Create a comment as a child of another comment (e.g. an answer)

$user = User::first();
$post = Post::first();

$parent = $post->comments->first();

$comment = $post->comment([
    'title' => 'Some title',
    'body' => 'Some body',
], $user, $parent);

dd($comment);

Update a comment

$comment = $post->updateComment(1, [
    'title' => 'new title',
    'body' => 'new body',
]);

Delete a comment

$post->deleteComment(1);

Count comments an entity has

$post = Post::first();

dd($post->commentCount());

Testing

$ phpunit

Security

If you discover a security vulnerability within this package, please send an e-mail to [email protected]. All security vulnerabilities will be promptly addressed.

Credits

This project exists thanks to all the people who contribute.

License

Mozilla Public License Version 2.0 (MPL-2.0).

laravel-commentable's People

Contributors

0plus1 avatar benjivm avatar dependabot-preview[bot] avatar faustbrian avatar kevinruscoe avatar ktotheoz avatar mfjordvald avatar osthafen avatar renovate[bot] avatar sam-ngu avatar tobischulz avatar tomiiide avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

laravel-commentable's Issues

vendor:publish doesn't publish or run migration (laravel 5.3.31)

  • Version: 2.0
  • PHP Version: 5.6

Expected behavior: publish the vendor assets and run migrations

Actual behavior:

Nothing to publish for tag [].
Nothing to migrate.

Steps to reproduce the behavior:

composer require faustbrian/laravel-commentable

Proposed solution:

appendTo() on boolean

-PHP Version: 7.1

Expected behavior:

creates child comment

Actual behavior:

FatalThrowableError in HasComments.php line 60:
Call to a member function appendTo() on boolean

Steps to reproduce the behavior:

     // Store method
     $post = Post::first();
     $parent = $post->comments->first();
       $comment = $post->comment([
           'title' => 'Some title',
           'body' => 'Some body',
       ], Auth::user(), $parent);

       dd($comment);
// HasComment Trait
public function comment($data, Model $creator, Model $parent = null)
    {
        $commentableModel = $this->commentableModel();

        $comment = (new $commentableModel())->createComment($this, $data, $creator); // This returns boolean.
       
        if (!empty($parent)) {
            $comment->appendTo($parent)->save();
        }

        return $comment;
    }

Proposed solution:

Please tell me

Add support for Laravel 5.8

- Conclusion: don't install laravel/framework v5.8.1
- faustbrian/laravel-commentable 3.0.0 requires illuminate/database 5.3.* || 5.4.* || 5.5.*

Suggestion : Set comment spam

Hi,
Thanks for this nice package,
What about comment spam ? it's really recommended for this system type :)
Just add an attribute spam, and a table coment_spam(comment_id, user_id) to get who does spam and count.
Regards :)

Pagination of comments

Hello,
When i try to paginate on collection of comments I get this BadMethodCallException,
Method Kalnoy\Nestedset\Collection::paginate does not exist.
in my Post model when i try this,
$post->comments->paginate(2); ,
but when i try this
$post->comments()->paginate(2);
I get N+1 query problem for getting creator relation details.
Best regards

Feature REquest

Nice to have:

  • Delete all comments per model
  • List all comments ( filter by * [date, user ,created_at attribute ])
  • adding extra (or dynamic ) comment attributes (eg, approved, visibility, comment_type, no_reply etc )

Can i Use this For Multi Auth User?

Lets Say i Have a User table, Employee table and Client Table...
All Have a been properly configure in config/auth.php

to provide a guard
user is default as web
and additional guard is employee and client...

I wanna know if it only accepts the user model or can accept other Model
that is the same as the User model...

thanks for reply

Trait 'BrianFaust\Commentable\HasComments' not found

  • Version: Laravel 5.3
  • PHP Version: 5.6

Expected behavior:

Trait is found.

Actual behavior:

Trait is not found..

Steps to reproduce the behavior:

composer require faustbrian/laravel-commentable
Add BrianFaust\Commentable\CommentableServiceProvider::class to config/app.php
php artisan vendor:publish --provider="BrianFaust\Commentable\CommentableServiceProvider" && php artisan migrate

Add Trait to Model definitions use BrianFaust\Commentable\HasComments;

Then use HasComments;

And error..

php 7.1

not working in php 7.0
i don't know how to resolve this problem without update php version

Issues running composer require faustbrian/laravel-commentable

Hey there,

Thanks for making this would love to have a go at using it.

When I run the composer require I get the following... any ideas how I can fix?

(I am running Laravel Framework version 5.2.45)

Thanks!

composer require faustbrian/laravel-commentable
Using version ^3.0 for faustbrian/laravel-commentable
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Conclusion: remove laravel/framework v5.2.45
    - Conclusion: don't install laravel/framework v5.2.45
    - faustbrian/laravel-commentable 3.0.0 requires illuminate/database 5.3.* || 5.4.* || 5.5.* -> satisfiable by illuminate/database[v5.3.0, v5.3.16, v5.3.23, v5.3.4, v5.4.0, v5.4.13, v5.4.17, v5.4.19, v5.4.27, v5.4.36, v5.4.9, v5.5.0, v5.5.16, v5.5.17, v5.5.2].
    - faustbrian/laravel-commentable v3.0.1 requires illuminate/database 5.3.* || 5.4.* || 5.5.* -> satisfiable by illuminate/database[v5.3.0, v5.3.16, v5.3.23, v5.3.4, v5.4.0, v5.4.13, v5.4.17, v5.4.19, v5.4.27, v5.4.36, v5.4.9, v5.5.0, v5.5.16, v5.5.17, v5.5.2].
    - don't install illuminate/database v5.3.0|don't install laravel/framework v5.2.45
    - don't install illuminate/database v5.3.16|don't install laravel/framework v5.2.45
    - don't install illuminate/database v5.3.23|don't install laravel/framework v5.2.45
    - don't install illuminate/database v5.3.4|don't install laravel/framework v5.2.45
    - don't install illuminate/database v5.4.0|don't install laravel/framework v5.2.45
    - don't install illuminate/database v5.4.13|don't install laravel/framework v5.2.45
    - don't install illuminate/database v5.4.17|don't install laravel/framework v5.2.45
    - don't install illuminate/database v5.4.19|don't install laravel/framework v5.2.45
    - don't install illuminate/database v5.4.27|don't install laravel/framework v5.2.45
    - don't install illuminate/database v5.4.36|don't install laravel/framework v5.2.45
    - don't install illuminate/database v5.4.9|don't install laravel/framework v5.2.45
    - don't install illuminate/database v5.5.0|don't install laravel/framework v5.2.45
    - don't install illuminate/database v5.5.16|don't install laravel/framework v5.2.45
    - don't install illuminate/database v5.5.17|don't install laravel/framework v5.2.45
    - don't install illuminate/database v5.5.2|don't install laravel/framework v5.2.45
    - Installation request for laravel/framework (locked at v5.2.45, required as 5.2.*) -> satisfiable by laravel/framework[v5.2.45].
    - Installation request for faustbrian/laravel-commentable ^3.0 -> satisfiable by faustbrian/laravel-commentable[3.0.0, v3.0.1].

Add support for Laravel 5.6

Hey, right now, only 5.4.* and 5.5.* are supported in the composer.json. Can you add support for 5.6?

faustbrian/laravel-commentable v3.1.0 requires illuminate/support 5.4.* || 5.5.*

Cannot install on fresh laravel 5.4.*

  • Version: 2.1.0
  • PHP Version: 7.0.14

Expected behavior:

Should be required fresh laravel project.

Actual behavior:

But it requires php ^7.1.* then it gives an error.

Proposed solution:

Laravel 5.4 requirement is PHP >= 5.6.4. Should change the php requirement.

Add support for Laravel 5.7

Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Conclusion: remove faustbrian/laravel-commentable v3.1.2
    - Conclusion: don't install faustbrian/laravel-commentable v3.1.2
    - Conclusion: don't install faustbrian/laravel-commentable v3.1.1
    - Conclusion: don't install faustbrian/laravel-commentable v3.1.0|don't install laravel/framework v5.7.1

Thanks for the cool package!

Creating child comment causes child to be parent to target parent comment

  • Version: ^2.1
  • PHP Version: 7.1.1

Expected behavior:

Threading comments, using $parent as outlined, to mark parent_id value of new comment to parent id

Actual behavior:

New comment becomes the parent instead.

Steps to reproduce the behavior:

Using the steps here: https://github.com/faustbrian/Laravel-Commentable#create-a-comment-as-a-child-of-another-comment-eg-an-answer

Proposed solution:

Shouldn't the parent be the one appending node?

https://github.com/faustbrian/Laravel-Commentable/blob/2566f2149505903f1d4892de566371f406387581/src/HasComments.php#L71-L73

Change to:
As seen here: https://github.com/lazychaser/laravel-nestedset#appending-and-prepending-to-the-specified-parent
// #2 Using parent node $parent->appendNode($comment);

Type error because of Return type declaration

If you define a custom model via config('laravel-commentable.model');

This error is thrown:

Type error: Return value of App\Company::comment() must be an instance of BrianFaust\Commentable\Models\Comment, instance of App\Comment returned

Because of the Return type declaration "Comment" here in HasComments.php :

public function comment($data, Model $creator, Model $parent = null): Comment
    {
        $commentableModel = $this->commentableModel();

        $comment = (new $commentableModel())->createComment($this, $data, $creator);

        if (! empty($parent)) {
            $parent->appendNode($comment);
        }

        return $comment;
    }

"Creator" morph columns not respecting Morph Map

Hello, this is a strange one, in the migration the following morph columns are created:

$table->morphs('commentable');
$table->morphs('creator');

Which correspond to these columns:

commentable_type
commentable_id
creator_type
creator_id

In my AppServiceProvider I define a morphMap() for all of my app's models:

    /**
     * Bootstrap any application services.
     */
    public function boot()
    {
        Relation::morphMap([
            'categories' => \App\Category::class,
            'epicor_contacts' => \App\EpicorContact::class,
            'users' => \App\User::class,
    ... etc.

The commentable_type column respects this map, however the creator_type column does not, e.g., it displays App\User instead of users.

Any idea how to fix this?

Can't install it

  • Laravel Version: 5.4
  • PHP Version: 7.0 / 5.6

Expected behavior:

Successfully install Laravel commentable

Actual behavior:

Using version ^2.0 for faustbrian/laravel-commentable
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

Problem 1
- faustbrian/laravel-commentable 2.1.4 requires php ^7.1 -> your PHP version (7.0.10) does not satisfy that requirement.
- faustbrian/laravel-commentable 2.1.3 requires php ^7.1 -> your PHP version (7.0.10) does not satisfy that requirement.
- faustbrian/laravel-commentable 2.1.2 requires php ^7.1 -> your PHP version (7.0.10) does not satisfy that requirement.
- faustbrian/laravel-commentable 2.1.1 requires php ^7.1 -> your PHP version (7.0.10) does not satisfy that requirement.
- faustbrian/laravel-commentable 2.1.0 requires php ^7.1 -> your PHP version (7.0.10) does not satisfy that requirement.
- Conclusion: don't install faustbrian/laravel-commentable 2.0.2
- Conclusion: don't install faustbrian/laravel-commentable 2.0.1
- Conclusion: remove laravel/framework v5.4.27
- Installation request for faustbrian/laravel-commentable ^2.0 -> satisfiable by faustbrian/laravel-commentable[2.0.0, 2.0.1, 2.0.2, 2.1.0, 2.1.1, 2.1.2, 2.1.3, 2.1.4].
- Conclusion: don't install laravel/framework v5.4.27
- faustbrian/laravel-commentable 2.0.0 requires illuminate/database 5.1.* || 5.2.* || 5.3.* -> satisfiable by illuminate/database[v5.1.1, v5.1.13, v5.1.16, v5.1.2, v5.1.20, v5.1.22, v5.1.25, v5.1.28, v5.1.30, v5.1.31, v5.1.41, v5.1.6, v5.1.8, v5.2.0, v5.2.19, v5.2.21, v5.2.24, v5.2.25, v5.2.26, v5.2.27, v5.2.28, v5.2.31, v5.2.32, v5.2.37, v5.2.43, v5.2.45, v5.2.6, v5.2.7, v5.3.0, v5.3.16, v5.3.23, v5.3.4].
- don't install illuminate/database v5.1.1|don't install laravel/framework v5.4.27
- don't install illuminate/database v5.1.13|don't install laravel/framework v5.4.27
- don't install illuminate/database v5.1.16|don't install laravel/framework v5.4.27
- don't install illuminate/database v5.1.2|don't install laravel/framework v5.4.27
- don't install illuminate/database v5.1.20|don't install laravel/framework v5.4.27
- don't install illuminate/database v5.1.22|don't install laravel/framework v5.4.27
- don't install illuminate/database v5.1.25|don't install laravel/framework v5.4.27
- don't install illuminate/database v5.1.28|don't install laravel/framework v5.4.27
- don't install illuminate/database v5.1.30|don't install laravel/framework v5.4.27
- don't install illuminate/database v5.1.31|don't install laravel/framework v5.4.27
- don't install illuminate/database v5.1.41|don't install laravel/framework v5.4.27
- don't install illuminate/database v5.1.6|don't install laravel/framework v5.4.27
- don't install illuminate/database v5.1.8|don't install laravel/framework v5.4.27
- don't install illuminate/database v5.2.0|don't install laravel/framework v5.4.27
- don't install illuminate/database v5.2.19|don't install laravel/framework v5.4.27
- don't install illuminate/database v5.2.21|don't install laravel/framework v5.4.27
- don't install illuminate/database v5.2.24|don't install laravel/framework v5.4.27
- don't install illuminate/database v5.2.25|don't install laravel/framework v5.4.27
- don't install illuminate/database v5.2.26|don't install laravel/framework v5.4.27
- don't install illuminate/database v5.2.27|don't install laravel/framework v5.4.27
- don't install illuminate/database v5.2.28|don't install laravel/framework v5.4.27

How can I successfully install laravel commentable?
It doesnt work on both php 7.0 and 5.6

Trait not found

I setup a Model as in documentation and create a comment.
I get this error: Trait 'BrianFaust\Commentable\HasCommentsTrait' not found

[Question] Get User comments

Hi @faustbrian,
I have a question for you.
I have two models (User / Books) which are both commentable (User can comment book / User can be commented by other users).

How to list all comments for a specific User ??
I tryed something like $user->comments->get() but get an empty array as response, but in DB this User has comments...

HasComment trait is on both models.

Feature Request add Guest support

Hello. I suggest add to this package:

  • Guest support, when add comment, user writes a email, and when user submit a comment, email must be verified, system send a email with confirmation on email user, and after confirmation comment will be published.
  • Add like/dislike comment
  • Add a type_comment (Good, Negative, Normal)
  • Add child comments (how on facebook)

Potentially unnecessary 7.1 requirement

Hey,

Looking through your commits (.e.g a4bc076), it looks like you're forcing the 7.1 requirement because of the return types. From what I can see they're all compatible with 7.0.

Worth downgrading the requirement?

Commentable service provider error

Hi,
I have been developing on Windows and whenver i switch to my Linux install i get this error when i run my project;

Declaration of BrianFaust\Commentable\CommentableServiceProvider::boot(): BrianFaust\Commentable\void must be compatible with BrianFaust\ServiceProvider\AbstractServiceProvider::boot(): BrianFaust\ServiceProvider\void

I am on Ubuntu 16.04
Laravel 5.4

Class not found

  • PHP Version: 7.08
    [Symfony\Component\Debug\Exception\FatalErrorException]
    Class 'BrianFaust\ServiceProvider\ServiceProvider' not found

无法安装

  • Version: 5.7
  • PHP Version: 7.0

php artisan vendor:publish

[Symfony\Component\Debug\Exception\FatalErrorException]
parse error, expecting ';'' or '{''

Does not work in Laravel 5.3

Issue / Motivation:

Unable to install package in Laravel 5.3

Expected behavior:

Installation would go through

Actual behavior:

- Installation request for draperstudio/laravel-commentable ^0.1.0 -> satisf                                                                                                                                                                                               iable by draperstudio/laravel-commentable[0.1.0].
- Conclusion: remove laravel/framework v5.3.4
- Conclusion: don't install laravel/framework v5.3.4
- draperstudio/laravel-commentable 0.1.0 requires illuminate/database 5.1.*                                                                                                                                                                                                || 5.2.* -> satisfiable by illuminate/database[v5.1.1, v5.1.13, v5.1.16, v5.1.2,                                                                                                                                                                                                v5.1.20, v5.1.22, v5.1.25, v5.1.28, v5.1.30, v5.1.31, v5.1.41, v5.1.6, v5.1.8,                                                                                                                                                                                                v5.2.0, v5.2.19, v5.2.21, v5.2.24, v5.2.25, v5.2.26, v5.2.27, v5.2.28, v5.2.31,                                                                                                                                                                                                v5.2.32, v5.2.37, v5.2.43, v5.2.45, v5.2.6, v5.2.7].
- don't install illuminate/database v5.1.1|don't install laravel/framework v                                                                                                                                                                                               5.3.4
- don't install illuminate/database v5.1.13|don't install laravel/framework                                                                                                                                                                                                v5.3.4

Steps to reproduce the behavior:

In project root run $ composer require draperstudio/laravel-commentable

Proposed solution:

Support Laravel 5.3, seem to work fine on 5.2

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.