laravelista / comments

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

Loading softdeleted commenter relation #151

Closed JonPurvis closed 3 years ago

JonPurvis commented 3 years ago

I'm trying to change comments with soft deleted commenter relations to still show the commenter, utilising withTrashed() but I've hit a problem. I've updated comments.php config file so it uses my new class:

'model' => \App\MyCommentClass::class,

in there, I've got:

/**
 * The user who posted the comment.
 */
public function commenter()
{
    return $this->morphTo()->withTrashed();
}

My class is extending Laravelista\Comments\Comment:

use Laravelista\Comments\Comment;

class MyCommentClass extends Comment

But it doesn't seem to be picking up the fact I specified my own class. Have I missed something here?

mabasic commented 3 years ago

If I am not mistaken, you don't need to extend the Comment model to implement this.

Your commenter model should have SoftDeletes trait added, and then you can access the "deleted" commenter with:

$comment->commenter()->withTrashed()->first();

or something like that.

Let me know if it works for you.

JonPurvis commented 3 years ago

Right you are, that works fine for me!

Thanks for the response 😄 👍