laravelista / comments

Native comments for your Laravel application.
MIT License
745 stars 144 forks source link

Different Comment Class #93

Closed borislav-itskov closed 4 years ago

borislav-itskov commented 4 years ago

Hey man,

good job on this package, it's really good :) I'm using it currently and it's helping me a lot.

One thing I wanted to mention - in the config options, we can choose to change our Comment model, if we wish to, to our own one. But if I create my own Comment model and place it there, some of the cool stuff this package has, like CommentPolicy, CommentController, etc become unusable because they have a hardcoded Comment model in them. In other words, they expect the Comment model from your package.

Maybe writing an interface, something like CommentInterface, and replacing the hardcoded Comment declarations in the package will allow for changing of models.

Also, If I'm mistaken somehow, please correct me :) I'll be glad to use this features with my own model.

mabasic commented 4 years ago

I have just noticed that now once you've mentioned it. Yes, I should make an interface for comment and use that instead, until then that functionality is broken.

Must admit that personally I haven't used that feature yet 😁

Glad you like the package. I'm going to fix this asap.

mabasic commented 4 years ago

@borislav-itskov I was trying to see the errors that you mentioned when using a different model, but it works for me somehow.

I can clearly see that the Comment model is hardcoded in the controller and policy and my logic tells me that this should not work when I use a different model, but both the policy and the controller resolve my custom model to be the comment model. Now, I assume that this is because I extend the Comment model in my custom model. I will paste my custom model bellow for you to see.

<?php

namespace App;

use Laravelista\Comments\Comment;

class Review extends Comment
{
    protected $table = 'comments';
}

Laravel Framework 7.9.2 PHP 7.4.5

Can you confirm my findings or send me the exact errors that you get?