cybercog / laravel-love

Add Social Reactions to Laravel Eloquent Models. It lets people express how they feel about the content. Fully customizable Weighted Reaction System & Reaction Type System with Like, Dislike and any other custom emotion types. Do you react?

Home Page:https://komarev.com/sources/laravel-love

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Get Reacterable for soft deleted (trashed) users

schwemmer opened this issue · comments

We have a bunch of soft deleted users and would like to still count their reactions (shown as "Deleted User"). The easiest way to do this is to change the relationship in the Reacter Model from this:

public function reacterable(): MorphTo
{
        return $this->morphTo('reacterable', 'type', 'id', 'love_reacter_id');
}

to this:

public function reacterable(): MorphTo
{
        return $this->morphTo('reacterable', 'type', 'id', 'love_reacter_id')->withTrashed();
}

However, the class is final and can not be extended. It would be great if we could somehow pass a parameter to also get reactions from soft deleted users in a future release.

See also #189

Can you call withTrashed like in issue you provided?

$item->getReacter()->reacterable()->withTrashed()->first()

@schwemmer another one way to do this:

  1. Copy \Cog\Laravel\Love\Reacter\Models\Reacter model to your app namespace
  2. Modify reacterable method to fit your needs
  3. Override loveReacter method in your User (Reacterable) model (it should return custom Reacter model)

Thanks a lot @antonkomarev, the first way you mentioned above actually works great!

Can we close an issue?

Yes, thank you!